我正在使用一些突然停止运行的代码。我将问题跟踪到.NET 4中的CallerMemberName功能
它似乎停止了工作,[CallerMemberName] String propertyName =""返回"",即使它是从属性"速度"中调用的。之前工作正常,我检查了该项目的目标是" .NET Framework 4"。知道是什么原因造成的吗?
物业代码:
public double speed
{
get { return _speed; }
set
{
_speed = value;
NotifyPropertyChanged();
}
}
并在此处理:
//events
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
void RealTimeDashboard_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case "speed":
NotifyPropertyChanged("speedDescription");
CalculateEfficency();
CheckEfficentConfigurations();
break;
}
}
编辑:已安装Microsoft BCL Portability Pack,它的行为相同但出现以下警告:
警告10类型' System.Runtime.CompilerServices.CallerMemberNameAttribute' in' D:\ Projects ... MainWindow.xaml.cs'与导入类型的冲突&System; Run.Runtime.CompilerServices.CallerMemberNameAttribute' in' d:\ Projects ... \ packages \ Microsoft.Bcl.1.1.10 \ lib \ net40 \ System.Runtime.dll'。使用&D; \ Projects .... \ MainWindow.xaml.cs'中定义的类型。 d:\ ...项目AnOtherClass.xaml.cs