Assembly: Packaging assembly information, can be dynamically loaded assembly
Assembly of acquiring several ways:
1, var ass1 = Assembly.Load ( "ClassLibrary1"); // item referenced in this assembly, this method can be used
2, var ass2 = Assembly.LoadFrom ( "c: //xxxx.dll"); // Get Assembly The full path to the assembly
3, var ass3 = personType.Assembly; // where specified Assembly Type
4、var ass4 = Assembly.GetAssembly(personType);//同上
5, var ass5 = Assembly.GetExecutingAssembly (); // set program contains a program entry
Type: reflecting obtained class information package may create an object that reflected
Gets the Type object in several ways:
1、assembly.GetType("反射Demo.Person"); 2、Type.GetType("反射Demo.Person"); 3、typeof(Person); 4、new Person().GetType();
Type objects common attributes:
animalType.IsArray // if array type animalType.IsImport // whether the COM type library introduced animalType.IsVisible // whether the code assembly may be accessed outside animalType.IsNestedPublic // If class is nested and declared public , true; otherwise false. animalType.IsNestedAssembly // whether it is nested and visible only within its own assembly. animalType.IsNestedFamily // whether it is nested and visible only within its own family. animalType.IsNested // nested within another type animalType.Namespace // namespace animalType.BaseType // directly inherited Type animalType.AssemblyQualifiedName // assembly qualified name animalType.IsSealed // whether declared as a sealed animalType.FullName // Get the fully qualified name of the type including its namespace, but does not include the assembly. animalType.Assembly // Get the type declaration in which the System.Reflection.Assembly animalType.Module // Get current defined therein System.Type module (DLL). animalType.GUID // obtain the GUID associated with System.Type.
Type objects commonly used methods:
was person type = typeof (Person); personType.GetProperties(); personType.GetProperty("Name"); personType.GetFields(); personType.GetField("_name"); personType.GetMethods(); personType.GetMethod("SayHello"); personType.GetMembers(); personType.GetMember("Name"); personType.MakeGenericType ( new new the Type [] { typeof ( String )}) the GetMethod (. " the SayHello " ) .Invoke (obj); // specified generic type of generic objects
MethodInfo Members:
mi.MakeGenericMethod ( new new the Type [] { typeof ( String )}) the Invoke (obj,. null ); // specified generic type generic method