[To celebrate my first year of programming I will ask a ‘stupid’ questions daily on my blog for a year, to make sure I learn at least 365 new things during my second year as a developer]
During my first year I heard a lot about this thing called ‘reflection’. I also heard various definitions, but I actually never really understood what it was. As with many questions, I forgot about it and it remained on my ‘I should find out this’-list, as I got the impression that it was something complicated that should be left for later.
Untill a few days ago. I was working on navigation on my Metro app, I got to think about reflection as I was wondering how GetType() and TypeOf() was working- I know what they DO but not HOW. And I suddenly realized what reflection is, and that I have been using it all along, as a programmer as well as for example at the gym.
Reflection lets you get information about a type or assembly at runtime in your code. It’s like when I do weighttraining at the gym, I need to check my techinque while I am doing the exercise, as I don’t know beforehand what to correct. So I will use the mirrors and ‘fetch information’ throughthe reflection, and then dynamically use that information so the exercise is correctly done.
I’ve found these two discussions on StackOverflow quite helpfull,
1.What exactly is Reflection and when is it a good approach?
2.When do you use reflection? Patterns/anti-patterns
-and they have also made me reconsider my usage of reflection and made me further look up “How slow is reflection”? I don’t have the answer for that yet, do you know? Please share!