How do I get the subscribers of an event?

前端 未结 4 2076
一个人的身影
一个人的身影 2020-11-29 08:17

I need to copy the subscribers of one event to another event. Can I get the subscribers of an event (like MyEvent[0] returning a delegate)?

If this is not possible I

4条回答
  •  暖寄归人
    2020-11-29 08:37

    If the event is one published by another class, you can't - at least, not reliably. While we often think of an event as being just a delegate variable, it's actually just a pair of methods: add and remove (or subscribe and unsubscribe).

    If it's your own code that's publishing the event, it's easy - you can make the add/remove accessors do whatever you like.

    Have a look at my article on events and see if that helps you. If not, please give more details about what you want to do, specifying which bits of code you're able to modify and which you aren't.

提交回复
热议问题