Reflection

In this chapter you will learn:

  1. What is Reflection

Get to know Reflection

Runtime type ID lets we identify a type during the code execution. Reflection enables you to obtain information about a type.

An instance of System.Type represents the metadata for a type.

Type Represents type declarations: class types, interface types, array types, value types, enumeration types, type parameters, generic type definitions, and open or closed constructed generic types.

You can get an instance of a System.Type by calling GetType on any object or with C#'s typeof operator:

System.Type is derived from an abstract class called System.Reflection.MemberInfo. MemberInfo defines the following abstract, read-only properties:

Return Type Method Name Meanings
Type DeclaringType The type of the class or interface in which the member is declared.
MemberTypes MemberType The type of the member.
string Name The name of the type.
TypeReflectedType The type of the object being reflected.

MemberTypes is an enumeration:

  • MemberTypes.Constructor
  • MemberTypes.Method
  • MemberTypes.Field
  • MemberTypes.Event
  • MemberTypes.Property

Next chapter...

What you will learn in the next chapter:

  1. Obtaining a Type
Home » C# Tutorial » Reflection
Reflection
Type
Type properties
Field reflection
Field Type
Field Attributes
FieldHandle
Field value
Set Field value
delegate reflection
Event reflection
Indexer reflection
Properties Reflection
Method
Parameter
Invoke
Type Instantiating
interface reflection
Generic type reflection
Reflection on nested Types
Subtype
Array reflection
Assembly