Pro EP 86 : What is reflection and what benefits we can get from it, how to retrieve property and method names ?
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
- Subscribe to my Weekly .NET Newsletter of C#/.NET with 6000+ Software Engineers.
- Promote yourself to 7500+ subscribers by Sponsoring my Newsletter
- Download my eBook at Gum Road which contains 30+ .NET Tips (With 2800+ Downloads)
- To get 100+ free and paid resources for learning C# and .NET visit this GitHub Repository