469,950 Members | 2,362 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

EventRaise and "pass thru"


How does one "pass thru" a Raised Event....

I am using the Adapter Pattern to sync up some different interfaces.
http://www.dofactory.com/Patterns/PatternAdapter.aspx
My Question is this:

ClassA raises an event.
I have a ClassB which is using ClassA , but does not expose it in anyway
(aka, no public property exposing the instanitated ClassA). (for reasons
like the pattern above)
ClassC is using ClassB.
When an event in ClassA is raised, I want ClassC to know about it, without
any knowledge (necessarily) that ClassB exists.
I know how to subscribe to Events, but I don't know how to "pass the event
thru" in this scenario.
If I need to provide more concrete information, then let me know.


May 4 '06 #1
3 2021
"sloan" <sl***@ipass.net> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...

How does one "pass thru" a Raised Event....

I am using the Adapter Pattern to sync up some different interfaces.
http://www.dofactory.com/Patterns/PatternAdapter.aspx
My Question is this:

ClassA raises an event.
I have a ClassB which is using ClassA , but does not expose it in anyway
(aka, no public property exposing the instanitated ClassA). (for reasons
like the pattern above)
ClassC is using ClassB.
When an event in ClassA is raised, I want ClassC to know about it, without
any knowledge (necessarily) that ClassB exists.

Declare a matching event in ClassB (same delegate type). Handle the ClassA
event in a ClassB instance member. Fire ClassB's event using the same
EventArgs-derived parameter. Change the object sender parameter to this if
you want to hide the internal ClassA object, pass through the original
sender to make ClassB transparent (although the receiver now gets a
reference to your private ClassA object).

I know how to subscribe to Events, but I don't know how to "pass the event
thru" in this scenario.
If I need to provide more concrete information, then let me know.

May 4 '06 #2
If you don't mind exposing the original sender, you can short-cut this; you
still need the matching declarations, but you don't need to catch and raise
at B:

public event SomeEventHandler SomeEvent {
add {innerObject.SomeEvent+=value;}
remove {innerObject.SomeEvent-=value;}
}

This way B doesn't ever get involved, other than as a means of hooking up to
A

Marc
May 4 '06 #3

I got it, thanks.

The part I was missing was

//ClassB code
protected virtual void OnInfoMessage(object sender, SqlInfoMessageEventArgs
e)
{
if (null!=InfoMessage ) {
InfoMessage(this, e);
}
}

The other parts (for completeness of the post) (These are coding items in
ClassB)

// in class declarations of ClassB
public event SqlInfoMessageEventHandler InfoMessage;


//method which wires up the ClassA event, to pass thru ClassB//this code is
in ClassB
private void WireUpPassThruEvent(SqlConnection sc)
{
if (null!=sc)
{
sc.InfoMessage += new EventHandler(this.OnInfoMessage);
}
}

The only part not here .. is the delegate, because I already had one defined
in the Sql class.

"Ben Voigt" <xyz> wrote in message
news:e8**************@TK2MSFTNGP02.phx.gbl...
"sloan" <sl***@ipass.net> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...

How does one "pass thru" a Raised Event....

I am using the Adapter Pattern to sync up some different interfaces.
http://www.dofactory.com/Patterns/PatternAdapter.aspx
My Question is this:

ClassA raises an event.
I have a ClassB which is using ClassA , but does not expose it in anyway
(aka, no public property exposing the instanitated ClassA). (for reasons
like the pattern above)
ClassC is using ClassB.
When an event in ClassA is raised, I want ClassC to know about it, without any knowledge (necessarily) that ClassB exists.

Declare a matching event in ClassB (same delegate type). Handle the

ClassA event in a ClassB instance member. Fire ClassB's event using the same
EventArgs-derived parameter. Change the object sender parameter to this if you want to hide the internal ClassA object, pass through the original
sender to make ClassB transparent (although the receiver now gets a
reference to your private ClassA object).

I know how to subscribe to Events, but I don't know how to "pass the event thru" in this scenario.
If I need to provide more concrete information, then let me know.


May 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by jissay | last post: by
6 posts views Thread by Vern | last post: by
4 posts views Thread by Benjamin Joldersma | last post: by
1 post views Thread by Tom | last post: by
16 posts views Thread by Gernot Frisch | last post: by
reply views Thread by mavicdog | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.