我CallerMemberName
在一个类的实现中使用了该属性,INotifyPropertyChanged
如MSDN中所述,如下所示:
public event PropertyChangedEventHandler PropertyChanged;
// This method is called by the Set accessor of each property.
// The CallerMemberName attribute that is applied to the optional propertyName
// parameter causes the property name of the caller to be substituted as an argument.
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
但是,使用默认参数不符合 CLS。但是CallerMemberName
只能与具有默认值的参数一起使用...有没有一种常用的方法来解决这种不一致,而无需使用硬编码的字符串参数调用 notify 方法?