سؤال

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