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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.