View Original: Http://www.cnblogs.com/feiyuhuo/p/5793606.html#commentform
1. Suppose you want to reflect a class in a DLL and not reference it (that is, an unknown type):
Assembly Assembly = assembly.loadfile ("Assembly path, cannot be relative path"); Loading assemblies (EXE or DLL)
Dynamic obj = assembly. CreateInstance ("The fully qualified name of the class (that is, including the namespace)"); To create an instance of a class
2. To reflect a class in the current project (that is, the current project already refers to it) can be:
Assembly Assembly = assembly.getexecutingassembly (); Get current Assembly
Dynamic obj = assembly. CreateInstance ("The fully qualified name of the class (that is, including the namespace)"); Creates an instance of the class, returns an object type, requires coercion of type conversion
3, can also be:
Type type = Type.GetType ("Fully qualified name of the class");
Dynamic obj = type. Assembly.createinstance (type);
4, different assemblies, then to load the call, the code is as follows:
System.Reflection.Assembly.Load ("assembly name (without file suffix name)"). CreateInstance ("namespace. Class name", false);
Such as:
Dynamic o = System.Reflection.Assembly.Load ("MyDll"). CreateInstance ("Mynamespace.a", false);
C # uses reflection to create an instance object of a class from a class name