Appendix X Reflection

A class’s type provides properties and methods that provide a wealth of information about the class. You can get a Type object representing a class by using typeof(TheClass) or by calling the GetType method on an instance of the class.

The following section summarizes the Type class’s most useful properties and methods. The sections after that summarize other useful reflection classes.

Type

The following table lists the Type class’s most useful properties.

PropertyDescription
AssemblyGets the assembly where the type is declared.
AttributesGets the type’s attributes.
BaseTypeGets the type’s parent class.
ContainsGenericParametersIndicates whether the type has generic type parameters.
CustomAttributesGets the type’s custom attributes.
FullNameGets the type’s fully qualified name, which includes the type’s namespace but not its assembly.
IsAbstractReturns true if the type is abstract.
IsArrayReturns true if the type is an array.
IsAutoLayoutReturns true if the type’s fields are laid out automatically by the CLR.
IsByRefReturns true if the type is passed by reference.
IsClassReturns true if the type is a class.
IsCOMObjectReturns true if the type is a COM object.
IsEnumReturns true if the type is an enumeration.
IsExplicitLayoutReturns true if the type’s fields are laid out explicitly.
IsGenericTypeGets a value indicating whether the current type is a generic type.
IsImportReturns true if the type was imported from a COM library.
IsInterface ...

Get C# 5.0 Programmer's Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.