How do I … use Extension Methods in VB.Net and compile and use them in multiple projects

If you take the following example. Please note:

  • Import CompilerServices
  • Namespace
  • Public Module
  • <Extesion()> attribute

Compile as normal into a dll and reference this dll in another project.
Then to use this extension import the Namespace dll root namespace .NewFeatures to the top of the class/form that you wish to use it on. Should then work.


Imports System.Runtime.CompilerServices

Namespace NewFeatures
Public Module BindingSourceExtension

<Extension()> _
Sub RemoveFilterSort(ByVal aBindingSource As BindingSource)
If aBindingSource.Filter IsNot Nothing Then aBindingSource.RemoveFilter()
If aBindingSource.Sort IsNot Nothing Then aBindingSource.RemoveSort()
End Sub

End Module
End Namespace



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: