It is not passed to null as a method - it passes it as a "target expression", that is, what it calls the method on. This value is null because OfType is a static method, so it does not need a target.
The call point of MakeGenericMethod is that GetCurrentMethod() returns an open version, i.e. OfType<> instead of OfType<YourType> .
Queryable.OfType itself should not contain any logic to discard any values. This is up to the LINQ provider. The point of Queryable.OfType is to create an expression tree to include the call in OfType , so that when the LINQ provider ultimately needs to convert it to its own format (like SQL), it knows that OfType was called.
This is how Queryable works - basically it allows the provider to see the entire query expression as an expression tree. That's all he wanted to do - when the provider is asked to translate this into real code, thatβs where the magic happens.
Queryable could not do the work itself - it has no idea what data the provider stores. How could this OfType with OfType semantics, not knowing if the SQL, LDAP data store or anything else was stored? I agree that it takes some time to get your head around :)
Jon skeet
source share