Re: It it possible to redirect events?



On Dec 11, 4:46 am, "Nicholas Paldino [.NET/C# MVP]"
<m...@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Sin Jeong-hun,

You could call the GetInvocationList method on the delegate and that
will give you an array of individual delegates that you could the attach
(one-by-one) to the ItHappened event on the Item class.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"Sin Jeong-hun" <typing...@xxxxxxxxx> wrote in message

news:49b669ab-ff6f-46d7-b44f-f99ebb7233cf@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



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.

Thank you for the simple and easy answer. I'll look into the method.
.



Relevant Pages

  • Re: It it possible to redirect events?
    ... You could call the GetInvocationList method on the delegate and that ... will give you an array of individual delegates that you could the attach ... public event ItemEventHandler ItHappened; ... the Manager, and the Manager has many 'Items'. ...
    (microsoft.public.dotnet.languages.csharp)
  • It it possible to redirect events?
    ... public event ItemEventHandler ItHappened; ... public Manager ... void OnItHappened ...
    (microsoft.public.dotnet.languages.csharp)