title: castle dynamic proxy PropertyChanged called before value changed
body: <p>I create an unit test library with the following code, it tries to proxy an INotifyPropertyChanged, and listen on it.</p>
  
  <pre><code>using System;
  using System.ComponentModel;
  using System.Runtime.CompilerServices;
  using Castle.Core;
  using Castle.DynamicProxy;
  using Castle.MicroKernel.Registration;
  using Castle.Windsor;
  using Microsoft.VisualStudio.TestTools.UnitTesting;
  using Component = Castle.MicroKernel.Registration.Component;
  
  namespace UnitTestWinsorContainer {
      [TestClass]
      public class UnitTestDynamicProxy {
          public static IWindsorContainer Container { get; protected set; }
  
          [ClassInitialize]
          public static void TestInit(TestContext tc) {
              Container = new WindsorContainer();
              Container.Register(Classes.FromThisAssembly().BasedOn&lt;IInterceptor&gt;());
              Container.Register(Component.For(typeof(DummyViewModel))
                  .Interceptors(InterceptorReference.ForType&lt;DummyInterceptor&gt;()).Anywhere);
          }
  
          [TestMethod]
          public void TestResolve() {
              Console.WriteLine("Test Starts");
              var i = Container.Resolve&lt;DummyViewModel&gt;();
              Assert.AreEqual(i.GetType().Name, "DummyViewModelProxy");
              i.PropertyChanged += OnPropertyChanged;
              i.Qty = 100;
              Console.WriteLine($"Get Qty after PropertyChanged of Proxy Qty=[{i.Qty}]");
  
              var j = new DummyViewModel();
              j.PropertyChanged += OnPropertyChanged;
              j.Qty = 100;
          }
  
          private static void OnPropertyChanged(object sender, PropertyChangedEventArgs e) {
              var d = sender as DummyViewModel;
              if (d != null) Console.WriteLine($"PropertyName=[{e.PropertyName}] Qty=[{d.Qty}]");
          }
      }
  
      public class DummyInterceptor : IInterceptor {
          public void Intercept(IInvocation invocation) {
              invocation.Proceed();
          }
      }
  
      public class DummyViewModel : Bindable {
          private int qty;
  
          /// &lt;summary&gt;
          ///     My Property
          /// &lt;/summary&gt;
          public int Qty {
              get { return qty; }
              set { SetProperty(ref qty, value); }
          }
      }
  
      public class Bindable : INotifyPropertyChanged {
          public event PropertyChangedEventHandler PropertyChanged;
  
          protected virtual bool SetProperty&lt;T&gt;(ref T storage, T value, [CallerMemberName] string propertyName = null) {
              if (Equals(storage, value)) return false;
  
              storage = value;
              RaisePropertyChanged(propertyName);
  
              return true;
          }
  
          protected virtual bool SetProperty&lt;T&gt;(ref T storage, T value, Action onChanged,
              [CallerMemberName] string propertyName = null) {
              if (Equals(storage, value)) return false;
  
              storage = value;
              onChanged?.Invoke();
              RaisePropertyChanged(propertyName);
  
              return true;
          }
  
          protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) {
              OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
          }
  
          protected virtual void OnPropertyChanged(PropertyChangedEventArgs args) {
              PropertyChanged?.Invoke(this, args);
          }
      }
  }
  </code></pre>
  
  <p>test will succeed, but the output console writes </p>
  
  <pre><code>Test Starts
  PropertyName=[Qty] Qty=[0]
  Get Qty after PropertyChanged of Proxy Qty=[100]
  PropertyName=[Qty] Qty=[100]
  </code></pre>
  
  <p>which means the first property changed event of the proxy is called when the underlying value is not changed.</p>
  
  <p>why is that? Am i doing something wrong?</p>