Injects INotifyPropertyChanging code into properties at compile time.
C# F#
Clone or download
Latest commit cf0913c Jun 24, 2018

README.md

Chat on Gitter NuGet Status

This is an add-in for Fody

Icon

Injects INotifyPropertyChanging code into properties at compile time.

Introduction to Fody

The nuget package

https://nuget.org/packages/PropertyChanging.Fody/

PM> Install-Package PropertyChanging.Fody

Your Code

[ImplementPropertyChanging]
public class Person
{
    public string GivenNames { get; set; }
    public string FamilyName { get; set; }

    public string FullName
    {
        get
        {
            return string.Format("{0} {1}", GivenNames, FamilyName);
        }
    }

}

What gets compiled

public class Person : INotifyPropertyChanging
{
    public event PropertyChangingEventHandler PropertyChanging;

    string givenNames;
    public string GivenNames
    {
        get { return givenNames; }
        set
        {
            if (value != givenNames)
            {
                OnPropertyChanging("GivenNames");
                OnPropertyChanging("FullName");
                givenNames = value;
            }
        }
    }

    string familyName;
    public string FamilyName
    {
        get { return familyName; }
        set 
        {
            if (value != familyName)
            {
                OnPropertyChanging("FamilyName");
                OnPropertyChanging("FullName");
                familyName = value;
            }
        }
    }

    public string FullName
    {
        get
        {
            return string.Format("{0} {1}", GivenNames, FamilyName);
        }
    }

    public virtual void OnPropertyChanging(string propertyName)
    {
        var propertyChanging = PropertyChanging;
        if (propertyChanging != null)
        {
            propertyChanging(this, new PropertyChangingEventArgs(propertyName));
        }
    }
}

Icon

Icon courtesy of The Noun Project

Contributors

More Info