Monday, November 12, 2012

using Reflection & Delegates to call the private parts of product

Short time ago I faced with a case when I need to call the private method. There are a lot of people who forget to make some methods public or just prefer internal. There are also other ones, who like to use the "private" instead of "protected". I don't want to write a lot about all these people because their places in hell have been already prepared.
So I derived from a parent class, overridden the virtual method and faced with the following issue: the overridden method calls private ones. I have 2 obvious ways how to handle this:
  1. Bring the implementation of the private method into my class;
  2. Use the Reflection.
The #1 approach is bad because... because I want to write you about the Reflection :)
actually I hope you know why it's unacceptable.