E
earth
If I have a class call it ClassA which is an aggregate of ClassB.
ClassA delegates to ClassB (I mean that in the English sense of the
word not in the C# reserved word sense). So for instance
ClassA.MyMethod calls ClassB.MyMehtod.
ClassA also has an event but the event is actually raised by ClassB.
The event can be called FooRaised.
The handler of the event will be on a third class ClientClass and
ClientClass will call ClassA.FooRaised += FooRaisedHandler.
Now,
I could have and event handler in ClassA that is hooked to the exposed
event of ClassB. When ClassB raises the event the ClassA handler will
raise the event on ClassA and the ClientClass.FooRaisedHandler will be
called.
However I don't want a handler in ClassA to be hooked to the event on
ClassB and effectively pass the event on. I want the handler in
ClientClass to be passed through to the event in ClassB so that when
ClassB raised the event the handler on ClientClass is called directly.
I could do this in other languages because events have accessor
methods where the handler is passed. In the set accessor I would
assign the handler to the aggregated class. In C# it does not appear
that events have accessor methods. This seems like a great big hole.
Is there a way to pass though the handler as I described?
I have considered a method on ClassA that accepts the event handler
type and will assign it to the event in ClassB but it is not really
the right way to expose an event.
ClassA delegates to ClassB (I mean that in the English sense of the
word not in the C# reserved word sense). So for instance
ClassA.MyMethod calls ClassB.MyMehtod.
ClassA also has an event but the event is actually raised by ClassB.
The event can be called FooRaised.
The handler of the event will be on a third class ClientClass and
ClientClass will call ClassA.FooRaised += FooRaisedHandler.
Now,
I could have and event handler in ClassA that is hooked to the exposed
event of ClassB. When ClassB raises the event the ClassA handler will
raise the event on ClassA and the ClientClass.FooRaisedHandler will be
called.
However I don't want a handler in ClassA to be hooked to the event on
ClassB and effectively pass the event on. I want the handler in
ClientClass to be passed through to the event in ClassB so that when
ClassB raised the event the handler on ClientClass is called directly.
I could do this in other languages because events have accessor
methods where the handler is passed. In the set accessor I would
assign the handler to the aggregated class. In C# it does not appear
that events have accessor methods. This seems like a great big hole.
Is there a way to pass though the handler as I described?
I have considered a method on ClassA that accepts the event handler
type and will assign it to the event in ClassB but it is not really
the right way to expose an event.