JetBrains Rider 2026.1 Help

代码检查:可能违反 'ValueRange'/'NonNegativeValue' 特性

此检查会报告可能违反 [ValueRange][NonNegativeValue]约定的整数值。 JetBrains Rider通过 控制流分析跟踪整数值范围,并在赋值或实参超出允许区间时发出警告。

解决方法是更改值或相关逻辑,以确保赋值在声明范围内。

示例

using JetBrains.Annotations; class C { [NonNegativeValue] public int Bar { get; set; } public void M() { Bar = -1; } }
using JetBrains.Annotations; class C { [NonNegativeValue] public int Bar { get; set; } public void M() { Bar = 0; } }
2026年 5月 8日