ReSharper 2025.2 Help

代码检查:无法解析文本参数中的符号

此代码检查根据各种 .NET Framework 合约验证字符串文字中使用的标识符名称,例如, System.Diagnostics.DebuggerDisplayAttributeSystem.ArgumentException 及其继承者的构造函数参数。

让我们看看它如何与 System.ArgumentException 及其继承者一起工作。 paramName 参数在 System.ArgumentException 及其派生类(例如 System.ArgumentNullExceptionSystem.ArgumentOutOfRangeException 等)的构造函数中,期望提供导致异常的参数名称,该名称将出现在堆栈跟踪中,以帮助您快速找到问题的根源。 因此,如果参数中的文字与抛出异常的方法的任何参数都不对应,ReSharper 会发出警告。 此外,ReSharper 知道 paramName 参数在不同签名中的位置,如下面的示例所示。

public void Foo(object value) { if(value == null) // Warning for unresolved symbol, where paramName is the first argument throw new ArgumentNullException("bad value", "value is null"); if(!(value is string)) // Warning for unresolved symbol, where paramName is the second argument throw new ArgumentException("bad value", "value is not string"); // do something }
最后修改日期: 2025年 9月 27日