title: Fire INotifyPropertyChanged.PropertyChanged via Reflection
body: <p>I'm trying to fire PropertyChanged via reflection and I'm having some issues.</p>
  
  <p>The following code works:</p>
  
  <pre><code>public abstract class ViewModelBase : INotifyPropertyChanged
  {
      public event PropertyChangedEventHandler PropertyChanged;
  
      private string m_test = string.Empty;
  
      public string Test
      {
          get
          {
              return m_test;
          }
          set
          {
              m_test = value;
              Notify();
          }
      }
  
      protected void Notify([CallerMemberName] string name = null)
      {
          var handler = PropertyChanged;
          if (handler != null &amp;&amp; name != null)
          {
              handler(this, new PropertyChangedEventArgs(name));
          }
      }
  }
  
  public class ViewModel : ViewModelBase
  {
      private string m_test2 = string.Empty;
      public string Test2
      {
          get
          {
              return m_test2;
          }
          set
          {
              m_test2 = value;
              Notify();
          }
      }
  }
  </code></pre>
  
  <p>However, I have added an extension method to INotifyPropertyChanged that would raise it via reflection.</p>
  
  <p>Instead of <code>Notify()</code> I could call <code>this.Notify()</code> instead, which is defined like so:</p>
  
  <pre><code>    /// &lt;summary&gt;
      /// Invoke sender's PropertyChanged event via Reflection
      /// &lt;/summary&gt;
      /// &lt;param name="sender"&gt;sender of the event&lt;/param&gt;
      /// &lt;param name="prop"&gt;The Property name that has changed&lt;/param&gt;
      public static void NotifyPropertyChanged(this INotifyPropertyChanged sender, [CallerMemberName] string prop = null)
      {
          var senderType = sender.GetType();
          var methodInfo = senderType.GetField("PropertyChanged", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
          if (methodInfo != null)
          {
              var delegates = (MulticastDelegate)methodInfo.GetValue(sender);
              if (delegates != null)
              {
                  foreach (var handler in delegates.GetInvocationList())
                  {
                      handler.Method.Invoke(handler.Target, new object[] { sender, new PropertyChangedEventArgs(prop) });
                  }
              }
          }
      }
  </code></pre>
  
  <p>Unfortunately, <code>GetField</code> returns null for <code>ViewModel</code> in the example above.</p>
  
  <p>Is there a way to reflect the parent's event? </p>
  
  <p>I'm thinking of iterating over the base classes, but I'm hoping for a better/easier way.</p>