Introduction to Reflection
Explore how to use reflection in C# to obtain detailed type information at runtime. Understand the key classes and methods in System.Reflection that let you inspect methods, properties, constructors, and assemblies in your applications.
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 ...