Ryan Harrison
My blog, portfolio and technology related ramblings
C# - Write code indirectly using reflection
29 Aug 2013
You can use the reflection features in C# to write your normal code in an indirect manner. No idea why you would want to do something like this, but it gives an idea of the control you get when using reflection.
In this example we have a small class wrapping two integers inside their own properties. First of all an object is created, the properties set, and the .ToString() method result passed into a Console.WriteLine using the conventional way. The exact same thing happens again but now indirectly through the use of reflection. As you can see it takes up nearly three times more code to to the exact same thing using reflection but you at least get the same result.