Reflection allows you to write code that can inspect various aspects about the code itself.
It enables you to do simple things like:
-
Check the type of an object at runtime (simple calls to
typeof()
for example) -
Inspect the Attributes of an object at runtime to change the behavior of a method (the various serialization methods in .NET)
To much more complicated tasks like:
- Loading an assembly at runtime, finding a specific class, determining if it matches a given Interface, and invoking certain members dynamically.
The earlier is much more common usage. The later is helpful to developers working on plug-in architectures for their applications or people who want to swap assemblies at runtime depending on configuration changes.