Injects INotifyPropertyChanging code into properties at compile time.
See Milestones for release notes.
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.
See also Fody usage.
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.
[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);
}
}
}
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));
}
}
}
- AccessBeforeValue
- Attributes
- EqualityChecking
- EventInvokerSelectionInjection
- ExampleUsage
- NotificationInterception
- On_PropertyName_Changing
- PropertyDependencies
- Options
- WeavingWithoutAddingAReference
Icon courtesy of The Noun Project