Extension method and dynamic object

后端 未结 3 2180
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 04:50

I am going to summarize my problem into the following code snippet.

List list = new List() { 5, 56, 2, 4, 63, 2 };
Console.WriteLine(li         


        
3条回答
  •  耶瑟儿~
    2020-11-22 05:17

    To expand on Jon's answer, the reason this doesn't work is because in regular, non-dynamic code extension methods work by doing a full search of all the classes known to the compiler for a static class that has an extension method that matches. The search goes in order based on the namespace nesting and available using directives in each namespace.

    That means that in order to get a dynamic extension method invocation resolved correctly, somehow the DLR has to know at runtime what all the namespace nestings and using directives were in your source code. We do not have a mechanism handy for encoding all that information into the call site. We considered inventing such a mechanism, but decided that it was too high cost and produced too much schedule risk to be worth it.

提交回复
热议问题