JetBrains Rider 2026.1 Help

代码检查:可能存在误导的 'DefaultValueAttribute' 用法来定义可选参数值。

此检查会报告使用 DefaultValueAttribute 来定义可选参数的默认值。 DefaultValueAttribute 不是可选参数元数据的正确特性。

示例

using System.Runtime.InteropServices; using System.ComponentModel; void Log([Optional, DefaultValue(1)] int level) { }

这看起来像可选参数声明,但 DefaultValueAttribute 用于其他场景,在这里可能具有误导性。

如何修复

此检查没有专用的快速修复方案。 请对可选参数使用 DefaultParameterValueAttribute

using System.Runtime.InteropServices; void Log([Optional, DefaultParameterValue(1)] int level) { }
2026年 5月 8日