Reactive - kswoll/someta GitHub Wiki

ReactiveUI provides a Fody extension (that I originally authored), but using this framework, you can just do it yourself, if you wanted. It provides a good example of the sort of extensions you can author with minimal fuss:

[AttributeUsage(AttributeTargets.Property)]
public class ReactiveAttribute : Attribute, IPropertySetInterceptor
{
    public void SetPropertyValue(PropertyInfo propertyInfo, object instance, object oldValue, object newValue, Action<object> setter)
    {
        if (!Equals(oldValue, newValue))
        {
            setter(newValue);
            ((IReactiveObject)instance).RaisePropertyChanged(propertyInfo.Name);
        }
    }
}

The basic idea is you want to call RaisePropertyChanged when the value of the property changes. Here we use an IPropertySetInterceptor that can rather trivially do this for you without authoring your own Fody package.

Example usage:

class Program
{
    static void Main(string[] args)
    {
        var o = new TestClass();
        string lastValue = null;
        o.WhenAnyValue(x => x.TestProperty).Subscribe(x => lastValue = x);
        o.TestProperty = "foo";
        Console.WriteLine(lastValue);
    }
}

public class TestClass : ReactiveObject
{
    [Reactive]
    public string TestProperty { get; set; }
}
⚠️ **GitHub.com Fallback** ⚠️