How to call an extension method of a dynamic type?

后端 未结 2 1379
醉话见心
醉话见心 2021-01-07 17:28

I\'m reading the book \'C# in Depth, 2nd Edition\' of Jon Skeet. He said that we can call extension methods with dynamic arguments using two workarounds, just as

<         


        
2条回答
  •  一生所求
    2021-01-07 18:23

    Extension method just a syntactic sugar, it will be converted as a normal method calling by c# compiler. This conversion is dependent with current syntax context (Which namespaces are imported by using statement).

    Dynamic variable is process by runtime. this time, CLR cannot get enough syntax context information to deciding which extension method used. So, it is not work.

提交回复
热议问题