I. The effect of reflection:
View and traverse types and types of metadata, dynamically create type instances, dynamically invoke created instance methods and fields, properties, late-bound methods, and properties.
Two. Get the Type Object instance:
The core class of reflection,-type, encapsulates metadata about the type, which is the entry for reflection. When a type object is obtained, it is possible to obtain all information of this type, including fields, attributes, events, parameters, constructors, etc., based on the letters and methods provided by type.
static void Main (string[] args) { //1. Use the static method provided by the type class GetType () type T = Type.GetType ("System.IO.Stream"); Console.WriteLine (T.tostring ()); 2. Use the typeof operator Type t1 = typeof (System.IO.Stream); Console.WriteLine (t1); 3. Obtain the type object by using an instance string name = "String Type"; Type t2 = name. GetType (); Console.WriteLine (T2); Create a new test Project class library, name Testdll, add to Project citation Class1 c1 = new Class1 (); Type t3 = C1. GetType (); Console.WriteLine (C1); }
Three. Type and System.Reflection namespace organization and structure.
Add the code in the code above:
Console.WriteLine (T3. Name); Current member name Console.WriteLine (T3. FullName); Type full name Console.WriteLine (T3. Namespace);//Gets the namespace Console.WriteLine (T3. BaseType); The reference Console.WriteLine (T3. net) for the mapping type. Attributes);//Gets the properties associated with the System.Type. //......
Type provides basic information for obtaining a type. Such as: current object type, namespace, object and namespace full name, whether public etc... Can be viewed in F12 to type.
"C # Reflection-type class"