From the course: LINQPad Essential Training

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Replace reflection with the Uncapsulate method

Replace reflection with the Uncapsulate method - LINQ Tutorial

From the course: LINQPad Essential Training

Replace reflection with the Uncapsulate method

- [Narrator] The reflection APIs in .Net are powerful, use it to examine the types in any .Net assembly. We can learn about the type, what methods, what properties, we can even invoke methods via reflection. The downside is that there's a lot of ceremony needed to get through reflection working and the syntax can be verbose. LINQPad has the uncapsulate extension method it handles all the reflection code for us. For this example, I'm using some code from the LINQPad samples with some minor adjustments. I have this classical demo that has two private fields, one I've type int and one I've type double. And then I have a private method is a simple divide, this method that takes a parameter and uses that to divide this private field, and return those results. Benefit of using uncapsulate is that it lets us look at the private fields, properties and methods, and that can be useful for diagnostics and debugging. So, the way it works…

Contents