【发布时间】:2015-11-24 17:29:08
【问题描述】:
我丢失了源代码,不得不从 DLL 进行反编译,并且在 LINQ to SQL DataContext 类的代码中收到以下错误。
错误 CS0030 无法将类型 'bool' 转换为 'int'
看起来 VS 生成的代码出于某种奇怪的原因使用 int 而不是 bool。请参阅下面的星号线。我应该怎么做才能解决这个铸造错误?在这个类中使用了一百多次。
public int? OrderBy
{
get
{
return this._OrderBy;
}
set
{
int? nullable = this._OrderBy;
int? nullable1 = value;
**if ((nullable.GetValueOrDefault() != nullable1.GetValueOrDefault() ? 1 : (int)(nullable.HasValue != nullable1.HasValue)) != 0)**
{
this.SendPropertyChanging();
this._OrderBy = value;
this.SendPropertyChanged("OrderBy");
}
}
}
编辑: 这个问题的答案是“获得更好的反编译器”。上面的代码是由 Telerik Just Decompile 生成的。 ILSpy 生成真正有意义的代码。在这种情况下:
[Column(Storage = "_OrderBy", DbType = "Int", UpdateCheck = UpdateCheck.Never), DataMember(Order = 6)]
public int? OrderBy
{
get
{
return this._OrderBy;
}
set
{
if (this._OrderBy != value)
{
this.SendPropertyChanging();
this._OrderBy = value;
this.SendPropertyChanged("OrderBy");
}
}
}
这个问题可能应该被删除。在 cmets 中提供建议。
【问题讨论】:
-
看来你只是想要
if(this._OrderBy != value)
标签: c# .net linq linq-to-sql