Move method info lookups to shared internal classes
https://github.com/dotnet/efcore/pull/20628#discussion_r408419555
Note to implementer:the main goal here is removal of duplicates. It may be better to leave single-access MethodInfos co-located with their use. It may also make sense to have multiple shared internal classes.
Hi @ajcvickers / @smitpatel
I would like to pick this one up if no one else is working on this one.
I am thinking of creating separate shared classes, similar to EnumerableMethods for methods that are used in more than one places, like DateTime, DateOnly, string, etc. since they are being used in multiple places (in different providers SQLServer, SQLite, Cosmos db, etc).
@nikhil197 I believe this is no longer a direction we should go in.
We currently indeed use reflection to look up MethodInfos; some of these patterns are understood by the .NET linker, which then refrains from trimming those methods. In effect, this means that EF's pipeline causes a lot more methods to get preserved, even if they never actually get used by user code, only because they could in theory be used and would need to be translated. This results in binaries that are bigger than they need to be.
The alternative is to use string-based matching, where we look at the name of the method in the query pipline, and also at its DeclaringType. That refrains from directly referencing the method in a way that's visible to the linker.
This work is tracked by #26288; I'll go ahead and close this issue.