Pages

Thursday, November 20, 2008

REFLECTION AND ATTRIBUTES (Part Two) - The System.Type Members

Today I am going to continue my series of Reflection And Attributes Tutorial. Lets begin with System.Type Members.

System.Type Members

Once a Type object is created, the fun begins. You can use Type properties and methods to inspect the type’s constructors, methods, attributes, fields, interfaces, and events. Examples
of their use are provided throughout this chapter.

For each method that returns an array of types or members, there is a corresponding method (same name without the final “s”) that searches for a single member or value. For example, to return a Type reference to the IDictionary interface, you could use:

Type hType=Type.GetType("System.Collections.Hashtable");
// Return null if interface no inherited
Type inType = hType.GetInterface("IDictionary");

Core Note

Most of the Type methods include an overload with a BindingFlags parameter. BindingFlags is an enumeration that includes values that can be used to filter the reflection search for members and types. Some of its more useful members include NonPublic, Public, Static, and DeclaredOnly (not inherited).


that's it for today.

Related topic:

REFLECTION AND ATTRIBUTES (Part One)

Related Post:

Reflection – Finding Type Members

C# .NET Reflection : Obtaining a Type Object with Object.GetType()