How can I find all the handlers for calling "RaisePropertyChanged"?

I have a property similar to this:

    private ISomething currentSomething;
    public ISomething CurrentSomething
        get { return currentSomething; }
            if (!object.Equals(currentSomething, value))
                currentSomething = value;
                RaisePropertyChanged(() => CurrentSomething);


When the caller calls the call, the value is correctly wrapped in the field currentSomething

. However, after the line RaisePropertyChanged(() => CurrentSomething);

in one of the lists, there are two items in the currentSomething field that have been removed.

It seems clear to me that something in my code is subscribing to this property change event (and truncating the list that I need to leave alone). However, I cannot find this handler.

Is there a way to find all the subscribers for the RaisePropertyChanged event?

I figured out that with my goal. It had to do with control, which had a view model doing something to do it. I'm going to leave the question open in case anyone has a good answer, but I'm not stuck anymore.


source to share

1 answer

You can use the GetInvocationList () method for the event. If you have a PropertyChanged event on an instance of myObject (of type MyClass), you can get subscribers like this:

        var methodInfo = typeof (MyClass.PropertyChangedDelegate).GetMethod("GetInvocationList");
        var p = myObject.GetType().GetField("PropertyChanged", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(myObject);
        var subscriberDelegates = (Delegate[])methodInfo.Invoke(p, null);
        object[] subscriberObjects = subscriberDelegates.Select(sub => sub.Target).ToArray();


This will work even outside the class defining the event.



All Articles