In this blog, I’m explaining the concept of reflection class in C#.
Reflection allows an application to collect information about itself and also to manipulate on itself. It can be used to find all types in an assembly and/or dynamically invoke methods in an assembly. Reflection is the process by which a program can read its own metadata. A program is said to reflect on itself, extracting metadata from its assembly and using that metadata either to inform the user or to modify its own behavior.
Reflection use the System.Reflection namespace. System.Reflection contains the classes and interfaces that a managed view of loaded types, methods, and fields, with the ability to dynamically create and invoke types. It has contain Type class is the main class for the reflection functionality. Type class uses the System.Type namespace.
The role of reflection
In short, reflection provides the following features:
- View and traverse the information of the basic types (and their members) and the metadata inside assemblies.
- Late bind methods and properties.
- Dynamically create type instances (and can dynamically invoke the methods, fields, properties in created instances).