Resharper 和代码合约不能很好地协同工作
我正在使用 Resharper 5.x 进行编译时分析,它通常非常好,但它似乎没有将代码契约应用于其逻辑。我有类似以下内容的内容,但我在标记线上遇到了问题。
public void Method(int arg)
{
Contract.Requires(this.NullableValueType != null);
this.Method2(
arg,
this.NullableValueType.Value, // [1]
this.ReferenceType);
}
[1] 最终以“Possible 'System.InvalidOperationException'”突出显示。有没有办法在不关闭检查的情况下消除此错误?
I'm using Resharper 5.x to do compile-time analysis and it's usually pretty good about it, but it doesn't seem to be applying code contracts to its logic. I have something like the following, but I'm getting an issue on the marked line.
public void Method(int arg)
{
Contract.Requires(this.NullableValueType != null);
this.Method2(
arg,
this.NullableValueType.Value, // [1]
this.ReferenceType);
}
[1] ends up getting highlighted with "Possible 'System.InvalidOperationException'". Is there a way to get rid of this error without turning off the check?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然不可否认,Resharper 可以更加智能并考虑合同,但不幸的是目前它还没有。
我建议让这条线更加明确。当然,
您可以在“某事”所在的位置编写
一些无关紧要的事情,因为它永远不会发生(例如,
new ThatValueType()
)。While admittedly Resharper could be more intelligent and take contracts into account, unfortunately currently it doesn’t.
I would recommend to make the line more explicit. Instead of
you could write
where the “something” is, of course, something that doesn’t matter because it never happens (for example,
new ThatValueType()
).