Generic Disposal (Of T) Tips & Tricks


Tips/Tricks

 The following code example shows a custom generic disposal

    Public Sub DisposeObjects(Of T As IDisposable)(ByRef disposableObject As T)
        Dim disposable As IDisposable = CType(disposableObject, T)
        disposableObject = CType(Nothing, T)
        If (disposable IsNot Nothing) Then
            disposable.Dispose()
        End If
    End Sub



Usage:

Dim any as Foo = New Foo

DisposeObjects(CType(any, Foo))




 


Comments

Popular posts from this blog

مقدمة الي تشفير الحروف الأبجدية العربية

VB.NET Translucent Control using GDI+

Add Custom Event to a Class in VB.NET