I have 3 objects.
Object A has an event X that other objects can subscribe to.
Object B registers for Object A’s X event.
How do I deregister Object B from Object A’s X event from within Object C?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t – the point of events is that it encapsulates the pub/sub part so that no-one else can mess.
Now if you (object C) can act as a proxy for object B the whole time, that’s a different matter. If you expose your own event which object B subscribes to instead of it subscribing to object A – and if you subscribe to object A on behalf of object B, then there are various ways of unsubscribing from object A. But unless you’ve been involved in that process, what “right” have you to mess with another piece of code’s event handlers?
EDIT: Just to pick up on your reflection point… if you have the appropriate permissions then you may be able to find a field which backs the event. At that point you can examine it directly – but that still doesn’t mean you know which handlers have been added by Object B. You could find handler methods that are within the type object B or a nested type, but those don’t have to have been added by object B – and object B could have attached handlers from other classes. Basically there’s nothing to say “who” subscribed to an event – only what the handler is.