Hi all,
Recently I started using C#, I have a question: Can we redefine a class legally in C# ?
For example:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("testing");
}
When the user click the button, it shows up a message box
If one day I want to log this action temporary, or prevent all the MessageBox from showing up entirely in my application, how can I make it happen without modifying all the MessageBox.Show() in my code ?
I know that I could make a subclass from MessageBox , use override or New, but it is not what I want. I am looking for a language facility for changing the behavior of any class (any method) dynamically in my namespace.
For example, I imagine that there is a keyword, let say, "OnEvent"
So that I can write some magic code like this:
OnEvent MessageBox Show( )
{
myClass.log( );
this.Show( );
}
after that, whenever I call Show() method from MessageBox class, the method actually got "hijacked" and under my control.
Any advice or comment is also welcomed.
Jeff