In many cases, we need a way to access the property from the metadata, and C # provides support for the mapping to access the metadata. By initializing the MemberInfo type object, this object in the System.Reflection namespace can be used to discover the properties of the member and access the metadata.
System.reflection.memberinfoinf=typeof (MyMath);
Calls the TypeOf operator on the MyMath type, which returns a variable of type types generated by the inherited MemberInfo.
The next step is to call GetCustomAttributes on the MemberInfo object and pass the type of the desired property as a parameter to the GetCustomAttributes. We'll get an array of objects, and the type of each member of the array is bugfixattribute.
Get member information and use it to access custom properties
System.reflection.memberinfoinf=typeof (MyMath);
Object[]attributes;
attributes=
Attribute.GetCustomAttributes (inf,typeof (Bugfixattribute));
Iterate through all the properties
foreach (Objectattributeinattributes)
{
Bugfixattributebfa= (Bugfixattribute) attribute;
Console.WriteLine ("\nbugid:{0}", BFA. BugID);
Console.WriteLine ("Programmer:{0}", BFA. Programmer);
Console.WriteLine ("Date:{0}", BFA. Date);
Console.WriteLine ("Comment:{0}", bfa.comment);
}
}
Type discovery
We can study the content of a composite entity by mapping, and this method is useful if we want to create a tool that needs to display the inner information of the assembly or invoke the path in the assembly dynamically.
By mapping the method, we can know the type of a module, method, domain, attribute, and the signal of each method of that type, the interface supported by the class, and the superclass of the class. We can dynamically load a combination using the Assembly.Load static method in the following form:
Publicstaticassembly.load (AssemblyName)
You can then pass it to the core library.
Assemblya=assembly.load ("Mscorlib.dll");
Once the assembly is loaded, we can return a type Object array by calling GetTypes. The type object is the core of the mapping, which represents the type definitions of classes, interfaces, arrays, values, and enumerations.
Type[]types=a.gettypes ();
Combined recess returns an array of types that we can display using the FOREACH-LOOP structure, and the output will have several pages of documentation, and here's a short paragraph:
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