Introduction to Reflection
Obtain information on types while the program is running.
We'll cover the following...
Introduction
Every application is composed of classes and other types, as well as their methods, properties, indexers, and so on. Reflection lets us obtain type information while the program is running. For instance, we could discover what methods a class has, what properties it operates, and what interfaces it implements. Reflection is type discovery at runtime.
The reflective functionality of .NET is located in the System.Reflection
namespace. To obtain information on a type, we use the System.Type
class. This class has methods like:
-
GetMembers()
: This returns aMemberInfo[]
object. -
GetConstructors()
: This returns a ...