|
|
|
|
|
by kevingadd
1612 days ago
|
|
I don't have a bookmarked page about this, but essentially if you implement your own version of the extension methods from the Linq namespace, the compiler will prefer those over the IEnumerable<T> extension methods. If you want to debug this a great way to do it is to examine the generated binary in a decompiler and you should see which methods the compiler decided to use. The async/await support also works this way - it will just look for methods with an appropriate signature and try to use them if possible: https://devblogs.microsoft.com/pfxteam/await-anything/ For both of the above examples, it's sufficient to write extension methods that target a specific type, so you don't have to change the actual types you want to query or await - just provide extension methods. This means you can do it for types you didn't write, as well. For more advanced scenarios, you can write a query provider that consumes expression trees, and the compiler will generate an expression tree for your library to consume instead of calling a bunch of methods: https://docs.microsoft.com/en-us/archive/blogs/mattwar/linq-... |
|