Assuming I have only the class name of a generic as a string in the form of ‘MyCustomGenericCollection(of MyCustomObjectClass)’ and don’t know the assembly it comes from, what is the easiest way to create an instance of that object?
If it helps, I know that the class implements IMyCustomInterface and is from an assembly loaded into the current AppDomain.
Markus Olsson gave an excellent example here, but I don’t see how to apply it to generics.
Once you parse it up, use Type.GetType(string) to get a reference to the types involved, then use Type.MakeGenericType(Type[]) to construct the specific generic type you need. Then, use Type.GetConstructor(Type[]) to get a reference to a constructor for the specific generic type, and finally call ConstructorInfo.Invoke to get an instance of the object.