Why is the first parameter of an extension method skipped?

Oct 1, 2015 at 9:17 AM
Hello! Yesterday I investigated your code, because I wanted my extension method to work with Linq to Entity, so I needed to comment out the next lines in FunctionDelivery.cs:

line 96, method GetParameters
if (method.IsDefined(typeof(ExtensionAttribute), false) && parameter.Position == 0)
Why do we actually need those lines?
Oct 9, 2015 at 7:38 PM
The first parameter in the extension method is the instance of the type being extended.

Oct 9, 2015 at 8:14 PM
Quite obvious answer. I know, but WHY do we need to skip that parameter? Usually, the first parameter in an extension method supposes some actions with it. For example, myDate.ToUnix() converts myDate to Unix timestamp. If I want to use that method as a sql-function in linq to entity I need to leave the first parameter.
Oct 11, 2015 at 4:07 AM
I think that extending primitive/base types is in general not a good idea since - it is hard to create an extension that would be generic and meaningful in all cases where a type like that is being used. Having said that - the logic could be a bit smarter and detect if the first argument is a primitive type that has a corresponding EDM type and ignore it when it does not.