Why do extension methods fail to get resolved for dynamic types? [duplicate]
-
21-04-2021 - |
문제
Possible Duplicate:
Extension method and dynamic object in c#
For example:
var obj = new byte[] { 1, 2, 3 };
dynamic dobj = obj;
dobj.Count(); // fails
Enumerable.Count(dobj); // works
해결책
It doesn't work because knowing which extension method to call requires knowing what the source code looked like before it was compiled (including knowing which using
directives were present). At runtime this information is not available. The workaround you are using is a good approach.
제휴하지 않습니다 StackOverflow