. The relationship between the human meridian and the reflection-related classes in net combat

Source: Internet
Author: User

--1. Part members of a class

--2. How to remember the relationship between members

[Mytableattribute ("T_userinfo")]     Public classUserinfo:person, UserService {Private int_age2; Private int_age; [DisplayName ("Age")]         Public intAge {Get            {                return_age; }            Set{_age=value; }} [DisplayName ("name")]         Public stringName {Get;Set; }  Public voidShowuserinfo () {Console.WriteLine (string. Format ("Name:{0},age:{1}", Name, _age)); }        protected voidShowName () {Console.WriteLine ("ShowName:"+Name); }    }
[AttributeUsage (AttributeTargets.Class | AttributeTargets.Method, AllowMultiple =true, inherited =true)]     Public classMytableattribute:attribute {Private string_tablename;  PublicMytableattribute (stringname) {_tablename=name; }         Public stringName {Get{return_tablename;} }    }

--3. Assemblies

   // Loading Assemblies (brain)             // gets the specified assembly name under the current run directory            Assembly-Assembly.Load ("reflectiondemo");             // assembly.loadfile (), Assembly.LoadFrom () loads the assembly of the specified file

--4. Type

    //load all meridians of the central nervous//get all types under this Assemblytype[] Types =The .            GetTypes (); //gets the information for a class based on the full name of the Class (Life gate space. Class name)Type type1 =. GetType ("Reflectiondemo.person"); //Ignore case or cannot find the type throws an exception//Type type2 =.            GetType ("Reflectiondemo.person2", Throwonerror:true, Ignorecase:true); //get public Types in an assemblytype[] Publictypes =The .            Getexportedtypes (); //gets the type of the classType Classusertype =typeof(UserInfo); //get the type of an instanceUserInfo UI =NewUserInfo (); Type Instancetype=UI.            GetType (); //gets the name of the typeConsole.WriteLine (string. Format ("Typefullname:{0},typename:{1}", Instancetype.fullname, Instancetype.name)); //whether to inherit from a classConsole.WriteLine ("is inherited from a class-----"+typeof(UserInfo). IsSubclassOf (typeof(person))); //whether an interface is implemented (whether the implementation type of the interface is the specified type)Console.WriteLine ("whether an interface has been implemented-----"+typeof(UserService). IsAssignableFrom (typeof(UserInfo))); //is the type of publicConsole.WriteLine ("is the type of public-----"+ classusertype.ispublic);

--5. Fields, properties, methods, attributes

   //get field BindingFlags bit mark get field different way//T.getfield (); T.getfields ()FieldInfo fiage = T.getfield ("_age", BindingFlags.Public|BindingFlags.NonPublic|bindingflags.static|bindingflags.instance|bindingflags.declaredonly); //Get properties like fieldt.getproperties (); PropertyInfo Pi= T.getproperty (""); //Pi. CanRead;//can read//Pi. CanWrite;//can write//Get MethodMethodinfo[] Methods =T.getmethods (); MethodInfo Method= T.getmethod ("Showuserinfo"); //Get AttributesMytableattribute tabattr = T.getcustomattribute (typeof(Mytableattribute)) asMytableattribute; if(Tabattr! =NULL) {Console.WriteLine ("SELECT * from"+tabattr.name); }

Next, reflected data manipulation

. The relationship between the human meridian and the reflection-related classes in net combat

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.