EDIT: This is not a duplicate of how-do-i-reflect-over-the-members-of-dynamic-object, as I am not interested in finding out the members (I know those), but interested in hooking into the System.Reflection mechanism, so that frameworks/libraries can use my dynamic object.
Actual question:
I have objects of type DynamicObject. These objects will be consumed by libraries that operate on members and use reflection. I am wondering if there is a way to achieve the following, i.e. to make reflection return the correct member info (PropertyInfo):
public class TestDO : DynamicObject {
...
}
typeof(TestDO).getProperty("SomeProp"); // make this not return null
I strongly assume it's not possible. In that case, an explanation of why this will never work (Why can't there be such a hook into the reflection system) and potentially an alternative would be nice.
Some ideas are:
- Is it possible to generate the type information at runtime, so that I can just use
typeof(MyJITCreatedType)(something like byte buddy in the Java world)? - I have seen ICustomTypeProvider, but have no idea if that can be used (does not even exist in my project currently)?
- Is there some hook in DynamicObject I can implement?
Note:
- I cannot change the way the library consumes my object/uses reflection.
- I can potentially give information about which type is used (i.e. MyJITCreatedType instead of TestDO).
- I know the properties at runtime.
- I can change the implementation of TestDO