Pro EP 86 : What is reflection and what benefits we can get from it, how to retrieve property and method names ?

Muhammad Waseem
Become .NET Pro !
1 min readOct 28, 2023

What is reflection and what benefits we can get from it, how to retrieve property and method names ?

Reflection objects are used for obtaining type information at runtime.

The classes that give access to the metadata of a running program are in the System.Reflection namespace.

One of most common use case that you would have seen is getting name of Assembly at runtime.

We usually use it in Program.cs file and its code looks like this:

var assembly = typeof(Program).Assembly;

Reflection is useful in :

- Dynamic code inspection
- Viewing metadata at run time
- Creating new types at runtime
- Late binding to method and properties

In the code snippet you can see how can we get information about method and its properties at run time.

Whenever you’re ready, there are 4 ways I can help you

  1. Subscribe to my Weekly .NET Newsletter of C#/.NET with 6000+ Software Engineers.
  2. Promote yourself to 7500+ subscribers by Sponsoring my Newsletter
  3. Download my eBook at Gum Road which contains 30+ .NET Tips (With 2800+ Downloads)
  4. To get 100+ free and paid resources for learning C# and .NET visit this GitHub Repository

--

--