Reputation: 79
Say I have a class A and it subscribes to n different events ffrom different classes (Say event1 from class B and event2 from class C). At the time of disposing object of Class A, I want to unsubscribe it from all the events it attached to different classes. I want to do it programmatically i.e. I have access to the object of Class A and I want to know which events it has registered from different classes and then unsubscribe them. Is it possible?
Upvotes: 0
Views: 38
Reputation: 69260
No it isn't. Technically your class A
has no reference at all to the class B
and class C
. The reference goes the other way.
You have to keep track of the events in a field in A
and unsubscribe manually when disposing.
Upvotes: 2