Suppose I have three classes A,B and C generated via emit/reflection abilities of .NET framework, and emmiting object in following manner:
class A
{
B someField1;
C someField2;
}
I need to initialize someField1 and someField2 after creating object:
A someObject;
How to do this? The someObject type is object but I have no idea how to cast it to A type created dynamically and enter fields and initialize it. Thank’s in advance for help.
You cannot cast to a dynamically created type in your code, as the compiler cannot know that type.
You can do what you need in a couple of ways:
or