【发布时间】:2017-08-04 09:01:57
【问题描述】:
我在INotifyPropertyChanged 的类实现中使用了CallerMemberName 属性,如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方法?
【问题讨论】:
标签: c#-6.0 default-parameters cls-compliant