It it possible to redirect events?
- From: Sin Jeong-hun <typingcat@xxxxxxxxx>
- Date: Mon, 10 Dec 2007 11:31:48 -0800 (PST)
class Manager
{
public event ItemEventHandler ItHappened;
public Manager
{
Item i;
i.ItHappend+=new ItemEventHandler(OnItHappened);
}
void OnItHappened(...)
{
this.ItHappened();
}
}
class Item
{
public event ItemEventHandler ItHapped;
}
Above are simplified version of two classes. The client interacts with
the Manager, and the Manager has many 'Items'. This scheme works but
looks kind of a waste and overhead, because everytime an item fires
ItHapped, OnItHappened is called which simply fires the Manager's the
same event with the same parameters. I just wondered, if this thing
would be possible
class Client
{
void Init()
{
Manager m;
m.ItHappend += new ItemEventHandler(...);
~~~~~~~~~~~~~~~~~~~~~~ Let's call this thing
X
}
}
class Manager
{
public event ItemEventHandler ItHappened;
public Manager
{
Item i;
i.ItHappend+=somehow get X from Manager's ItHappend handlers;
}
}
If this is possible, then there's no need to call the trivial method
each time. Is it possible to get the handler list of the Manager's
ItHappened event at that point?
Thanks.
.
- Follow-Ups:
- Re: It it possible to redirect events?
- From: Peter Duniho
- Re: It it possible to redirect events?
- From: Nicholas Paldino [.NET/C# MVP]
- Re: It it possible to redirect events?
- Prev by Date: Re: Windows Installer Custom Action cannot do xcopy?
- Next by Date: Re: Why does Thread class not support IDisposable?
- Previous by thread: Getting Internet Explorer Security Settings
- Next by thread: Re: It it possible to redirect events?
- Index(es):
Relevant Pages
|