I have this object set:
Object A
Object AA: A
Object BB: A
Object CC: A
how do i create an object of type AA Given a string variable with "AA" in it? I've been looking at the Activator stuff but can't quite figure it out.
I have this object set:
Object A
Object AA: A
Object BB: A
Object CC: A
how do i create an object of type AA Given a string variable with "AA" in it? I've been looking at the Activator stuff but can't quite figure it out.
You need to get the Type
instance for AA
, then pass it to Activator.CreateInstance
.
Type myType = typeof(SomeTypeInProject).Assembly.GetType(typeName);
object instance = Activator.CreateInstance(myType);