Reflection does not actually work (as you expected) on types dynamic. You need to check IDynamicMetaObjectProviderand then use its methods to determine if a member is available in the type.
The problem is that dynamicit is perfectly acceptable for a type to add new members at run time. For example, see ExpandoObject . It only adds new members to the given operations, but you can just as easily create a dynamic type that always returns a valid member, regardless of what is passed to it, that is:
dynamic myType = new DynamicFoo();
Console.WriteLine(myType.Foo);
Console.WriteLine(myType.Bar);
Console.WriteLine(myType.Baz);
This can be done by overriding the get accessor and just making them always valid. In this case, the reflection could not say that it will work here ...
source
share