Skip to content

Fody/PropertyChanging

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

PropertyChanging.Fody

Chat on Gitter NuGet Status

Injects INotifyPropertyChanging code into properties at compile time.

This is an add-in for Fody

It is expected that all developers using Fody become a Patron on OpenCollective. See Licensing/Patron FAQ for more information.

Usage

See also Fody usage.

NuGet installation

Install the PropertyChanging.Fody NuGet package and update the Fody NuGet package:

PM> Install-Package Fody
PM> Install-Package PropertyChanging.Fody

The Install-Package Fody is required since NuGet always defaults to the oldest, and most buggy, version of any dependency.

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));
        }
    }
}

More Info

Icon

Icon courtesy of The Noun Project

About

Injects INotifyPropertyChanging code into properties at compile time.

Resources

License

Stars

Watchers

Forks

Packages

No packages published