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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top