How do I … use Extension Methods in VB.Net and compile and use them in multiple projects
09-Oct-1212 Leave a comment
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