What Is Reflection In C#?

We call “reflection” the ability that some programming languages have to inspect their own constructs dynamically. Using reflection, you can, for instance, load a class dynamically from an Assembly, test whether a given type has a specific member, and even create code dynamically.

To understand reflection in C#, there are a few basics you should understand about the hierarchy of its programming constructs:

Reflection should be employed when the problem cannot be solved using traditional methods.

Type.GetMethod Method (System)

private MethodInfo _method;
//Get private method with reflection
_method = typeof(MyClass).GetMethod("MyMethod", BindingFlags.NonPublic | BindingFlags.Instance);

BindingFlags Enum (System.Reflection)