Type get types Basic information Example

Source: Internet
Author: User


This article takes the following: http://blog.csdn.net/lhc1105/article/details/44279675, when we get to an object instance, we can take advantage of some of the methods provided by the type class to get basic and member information about the type:



    #region get the basic information for a type people people = new people () instance of the//people class {ID = "                10086 ", Name =" LHC "}; Type T = people.  GetType (); Gets the Type Object Console.WriteLine (T.name) through the instance,//Gets the name of the current Member Console.WriteLine (t.fullname);//Gets the type full Name Console.WriteLine (t.namespace);//Gets the namespace of the current Member Console.WriteLine (t.basetype);//Gets the type of the base class References to Console.WriteLine (T.underlyingsystemtype);//In. NET is a reference to the type mapped in Console.WriteLine (t.attributes);//Get TypeAttributes Bit token Console.WriteLine (t.isval                Uetype);//Whether it is a value type Console.WriteLine (T.ISBYREF);//Whether it is a reference pass Console.WriteLine (t.isenum);//Whether it is an enumeration                Console.WriteLine (T.isclass);//Whether it is a class Console.WriteLine (t.isinterface);//Whether it is an interface       Console.WriteLine (t.issealed);//Whether it is a sealed class Console.WriteLine (t.isprimitive);//Whether it is a base type         Console.WriteLine (t.isabstract);//Is abstract class Console.WriteLine (t.ispublic);//Whether public Conso Le. WriteLine (t.isnotpublic);//whether Private Console.WriteLine (t.isvisible);//assembly is visible #endregion



In addition to getting the basic information of the type, we can also get the properties of the type, fields, methods, etc. For example, you previously used Getfieldinfos to get a collection of fields and get the method with Getmethodinfos. In addition to the two used, there are methods for getting a collection of properties, constructor methods:


after these are obtained, the array is used to take the corresponding array, then a traversal operation can be performed, and if the type is passed in T, then the reflection will be more able to embody the advantage of universality.



I do not know that before you use a tool like reflector such as anti-compiler DLL, feel this kind of thing should also be done by reflection principle of it ....











Type get types Basic information Example

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.