Chaining events in .Net (Sometims it's just too easy)
Had the need to chain events today with some simple decorator-style objects. Scratched my head, tried a couple of solutions, didn't work. Wrote a EventForwarderClass which solved the problem. Sat down to write this blog entry and curse the framework. Then it struck me, did I even try to just add the event to the other event? No, of course not.
public interface A
{
event MyEvent;
}
public class B : A
{
....
}
public class C : A
{
public event MyEvent;
public C(A decorateMe)
{
....do stuff...
A.MyEvent += this.MyEvent;
}
}








0 Comments:
Post a Comment
<< Home