C # Reflection--------Creating an object instance
There are three ways to create object instances in C #
(1) through the System.Reflection.Assmbly method obtains the instance, mainly according to the class FullName and the constructor function parameter creation instance, including the private and the public, very powerful
public Object CreateInstance (string typeName);//Use case-sensitive method to find the specified type name, FullName,
public Object CreateInstance (string typeName, bool ignoreCase);//Use the specified type name, FullName, whether case sensitivity is determined by the parameter
Using a variety of parameters, Binder is null, does not know what, args is the parameter of the constructor, culture and activation can be null, do not know what
Public virtual Object CreateInstance (string typeName, bool IgnoreCase, BindingFlags bindingattr, Binder binder, object[] A RGS, CultureInfo culture, object[] activationattributes);
Examples of creating instances:
var obj = Assembly.LoadFrom (@ "d:\ application software \vs2017\c#\windowsformsapp16\classlibrary1\bin\debug\classlibrary1.dll"). CreateInstance (parametric)
(2) using System.activator static method CreateInstance to obtain the corresponding example
Public Static ObjectCreateInstance (type type);//Create an object instance based on a public parameterless constructor
public static object CreateInstance (type type, bool nonpublic), or true if common or non-public default constructors can match, or false if only public default constructors can match.
public static object CreateInstance (type type, object[] args, object[] activationattributes);//args as a constructor argument
public static object CreateInstance (type type, params object[] args);
public static object CreateInstance (type type, BindingFlags bindingattr, Binder binder, object[] args, CultureInfo culture );
public static object CreateInstance (type type, BindingFlags bindingattr, Binder binder, object[] args, CultureInfo culture , object[] activationattributes);
public static ObjectHandle CreateInstance (String assemblyname, String typeName);
public static ObjectHandle CreateInstance (String assemblyname, String TypeName, object[] activationattributes);
C # Reflection--------Creating an object instance