Applications of Reflection
Learn how to use reflection to inspect a type’s methods, implemented interfaces, and non-public members, and discover how to invoke those methods dynamically at runtime.
We'll cover the following...
Reflection allows us to reach deep into the metadata of our applications to analyze types and their internal structures dynamically. By using the System.Reflection namespace, we can uncover everything from public method signatures to hidden private fields that are otherwise inaccessible. This capability provides the foundation for building flexible tools like object mappers, debuggers, and unit testing frameworks.
Explore a type’s methods
Reflection provides programmatic access to all type metadata. For instance, we can easily obtain the list of a type's methods by using the GetMethods() method. This method returns an array of MethodInfo objects. We can learn about the method’s return type, as well as what parameters the method accepts, using the GetParameters() method: