Hello,
I thought to make a module and collect all my disposers inside, all with the same name but different input data types (overload), something like:
(the inner logic is not important, asking about the general idea/algorithm)
Module ModuleShredder
Friend Sub Disposer(ByVal MyCertificate As X509Certificate)
On Error Resume Next
If MyCertificate IsNot Nothing Then
MyCertificate.Reset()
MyCertificate = Nothing
End If
End Sub
Friend Sub Disposer(ByVal MyCollection As X509CertificateCollection, Optional ByVal RenewCollection As Boolean = False)
On Error Resume Next
If MyCollection IsNot Nothing Then
For Each MyCertificate As X509Certificate In MyCollection
MyCertificate.Reset()
MyCertificate = Nothing
Next
MyCollection.Clear()
MyCollection = Nothing
End If
If RenewCollection = True Then MyCollection = New X509CertificateCollection
End Sub
Friend Sub Disposer(ByRef InputMessage As MailMessage)
On Error Resume Next
If InputMessage IsNot Nothing Then
InputMessage.Reset()
InputMessage.Dispose()
End If
InputMessage = Nothing
End Sub
End Module
As you see all Subs have the same names overloading different data types.
Is this usage correct? I mean any problems might occur or logical usage errors?
Thanks for advise :)
- oh and I guess I should pass everything as ByRef right? Since going to be fully disposed?