Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Injects INotifyPropertyChanged code into properties at compile time
C# PowerShell F#

README.md

This is an add-in for Fody

Icon

Injects INotifyPropertyChanged code into properties at compile time.

Introduction to Fody

The nuget package NuGet Status

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

PM> Install-Package PropertyChanged.Fody

Your Code

NOTE: All classes that do not have [ImplementPropertyChanged] but still have INotifyPropertyChanged will have notification code injected into property sets.

[ImplementPropertyChanged]
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 : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

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

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

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

    public virtual void OnPropertyChanged(string propertyName)
    {
        var propertyChanged = PropertyChanged;
        if (propertyChanged != null)
        {
            propertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

Icon

Icon courtesy of The Noun Project

Contributors

More Info

Something went wrong with that request. Please try again.