Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have a string of the Type Name you can do something like this:</p> <pre><code>Assembly execAsm = Assembly.GetExecutingAssembly(); object instance = AppDomain.CurrentDomain.CreateInstanceAndUnwrap(execAsm.FullName, "RipperWorkbench.Classes.LoadManager"); // the type name cam come from a variable or someplace else. </code></pre> <p>then you can cast it to the type you need</p> <pre><code>Master.Enterprise ent = obj as Master.Enterprise; if (obj != null) { ... } </code></pre> <p>Or alternatively, have the object implement an interface: You have to be sure that the type is loaded into current AppDomain, otherwise the type can't be reflected.</p> <pre><code>Assembly asm = Assembly.GetExecutingAssembly(); // The executing assembly can change also; so you can load types from other assemblies // use this if the type isn't loaded in this AppDomain yet. //Assembly asm = Assembly.LoadFile("path to assembly here", new Evidence()); String typeToLoad = "Master.Enterprise"; // this can be from a config or database call Type objType = asm.GetType(typeToLoad, true); if (!objType.IsPublic) return null; // make sure the type isn't Abstract if (((objType.Attributes &amp; TypeAttributes.Abstract) == TypeAttributes.Abstract)) return null; // IEnterprise is the interface that all of the plugin types must implement to be loaded Type objInterface = objType.GetInterface("IEnterprise", true); if (objInterface == null) return null; var iri = (IEnterprise)Activator.CreateInstance(objType); return iri; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload