插件名称
PropertyChanged.Fody
获取方式
VS通过Nuget添加
实现原理
在编译的时候,再属性中实现INotifyPropertyChanged相关代码
相关特性
AddInotifyPropertyChangedInterface
自动对添加了此特性的类继承并实现INotifyPropertyChanged接口
[AddINotifyPropertyChangedInterface]
public class InfoModel
{
///属性
public string value{get; set;}
}
AlsoNotifyFor
属性具有上标记此属性后,若触发通知,同时会触发设置的其他属性的通知
[AddINotifyPropertyChangedInterface]
public class InfoModel
{
[AlsoNotifyFor("Name")]
public string FirstName { get; set; }
[AlsoNotifyFor("Name")]
public string LastName { get; set; }
public string Name { get; set; }//FirstName和LastName通知时会触发Name的通知
}
DoNotNotify
标识的属性不实现通知
[AddINotifyPropertyChangedInterface]
public class InfoModel
{
[DoNotNotify]
public string Name { get; set; }
}
DependsOn
指定那些属性变化的时候,通知当前属性变化
public class InfoModel
{
[DependsOn("FirstName", "LastName")]
public string FullName { get; set; }//FirstName和LastName变化时,通知当前属性变化
}
DoNotCheckEquality
不检查是否新值与旧值相等(默认会添加新旧值对比的代码)
[DoNotCheckEquality]
public string Value { get; set; }
默认属性 IsChanged(bool)
如果类中定义的IsChanged属性,则当此类中其他属性发生通知时,此值变为true
[AddINotifyPropertyChangedInterface]
public class Model
{
public string value{get;set;}
public bool IsChanged { get; set; }//当value值变化时,此值变更为true,并通知(必须为bool类型)
}