문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top