"C # Reflection-type class"

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.