If you have a string like Name, you can do something like this:
Assembly execAsm = Assembly.GetExecutingAssembly();
object instance = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(execAsm.FullName, "RipperWorkbench.Classes.LoadManager");
then you can apply it to the type you need.
Master.Enterprise ent = obj as Master.Enterprise;
if (obj != null)
{
...
}
Or, conversely, if an object implements an interface: you must be sure that the type is loaded into the current AppDomain, otherwise the type cannot be reflected.
Assembly asm = Assembly.GetExecutingAssembly();
String typeToLoad = "Master.Enterprise";
Type objType = asm.GetType(typeToLoad, true);
if (!objType.IsPublic)
return null;
if (((objType.Attributes & TypeAttributes.Abstract) == TypeAttributes.Abstract))
return null;
Type objInterface = objType.GetInterface("IEnterprise", true);
if (objInterface == null)
return null;
var iri = (IEnterprise)Activator.CreateInstance(objType);
return iri;
source
share