I have Class A which implements a large number of instances of Class B. Class B encapsulates an instance of Class C.
Class raises events which need to be handled by Class A. Class A does not need to know about Class C. Class C is passing back performance based statistics which A then needs to coalesce.
How do I create the events in Class B and connect them so that Class A can subscribe to Class B's events and receive the events from Class C?
An event is nothing more than a pair of methods wrapping a delegate field. You can override the default implementation of the add & remove methods in ClassB
to pass the value straight to the event in ClassC
:
public class ClassB
{
private ClassC m_C = new ClassC();
public event EventHandler MyEvent
{
add { m_C.MyEvent += value; }
remove { m_C.MyEvent -= value; }
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With