Linq, Extensions, Explain..

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
Any one know why it is stated in several of the documentations that such and such is an "Extension Class" for something, and when looked upon in the refractor it looks something like this:
(example used is for the DataTableExtensions)
VB.NET:
<Extension> _
Public Class DataTableExtensions
    ' Methods
    <Extension> _
    Public Shared Function AsDataView(Of T As DataRow)(ByVal source As EnumerableRowCollection(Of T)) As DataView
    <Extension> _
    Public Shared Function AsDataView(ByVal table As DataTable) As DataView
    <Extension> _
    Public Shared Function AsEnumerable(ByVal source As DataTable) As EnumerableRowCollection(Of DataRow)
    <Extension> _
    Public Shared Function CopyToDataTable(Of T As DataRow)(ByVal source As IEnumerable(Of T)) As DataTable
    <Extension> _
    Public Shared Sub CopyToDataTable(Of T As DataRow)(ByVal source As IEnumerable(Of T), ByVal table As DataTable, ByVal options As LoadOption)
    <Extension> _
    Public Shared Sub CopyToDataTable(Of T As DataRow)(ByVal source As IEnumerable(Of T), ByVal table As DataTable, ByVal options As LoadOption, ByVal errorHandler As FillErrorEventHandler)
    Private Shared Function LoadTableFromEnumerable(Of T As DataRow)(ByVal source As IEnumerable(Of T), ByVal table As DataTable, ByVal options As LoadOption?, ByVal errorHandler As FillErrorEventHandler) As DataTable
End Class

however if I the programmer who wishes to use this wonderful feature, try to utilize the Extension attribute in a similar fashion I get:

Extension can only be used on a Module, Sub, or Function

So who is wrong? are they just being...jerks...and preventing us from doing similar cool things, or is the refractor not displaying the declarations correctly?

Thanks
 
refractor
.Net Reflector, yeah?
So who is wrong? are they just being...jerks...and preventing us from doing similar cool things, or is the refractor not displaying the declarations correctly?
According to documentation DataTableExtensions is a class, so that is correct, it is also declared "static". If you look in the window that display the description for the selected node the class description is:
Defines the extension methods to the DataTable class. DataTableExtensions is a static class.
It's the same description found in documentation. Static means "shared" in VB, just about every topic page in documentation explain this (never seen the "static (Shared in Visual Basic)" phraze in Thread Safety note?), and extensions can only be defined in "static" classes. To define a shared class in VB you declare it as a "Module". So you can do exactly the same in VB.Net. As we've seen before Reflector is once again inaccurate in translation to VB.Net language.
 
Yea, sorry bout the mistake, refractor...that was probably confusing.

So basically, the Reflector doesn't convert to VB to accurately, and teh intellisense was accurate that I need to apply the "Extension" attribute to a Module. where all the methods are extension methods that deal with the specific class i wish to extend. Okay. Thanks, rather interesting the VB differentiation between module and class, but now i know.
 
Back
Top