Selectively firing events

  • Thread starter Thread starter john
  • Start date Start date
J

john

Hi,

I have a class that fires an event like this:

class MyClass
{
....
protected override void OnEvent(SomeEventArgs sea)
{
if (MyEvent!=null)
{
MyEvent(this,sea);
}
}
}

There are several subscriber. I want to be able to notify
only selected subscribers of the event, not all of them.
One way is to unsubscribe the unwanted ones, but this is
not an option as it would require more logic. Is there a
way to do some check in this block:


if (MyEvent!=null)
{
if (this is the object I want notified)
{
MyEvent(this,sea);
}
}

Or maybe check the invocation list?

Thanks !
 
How about separating your event into two separate events and having other
objects subscribe only to the necessary ones?
Your class should be able to fire events without knowing who is receiving
them in the other end.

Santiago
 
Back
Top