代码检查:“ref” 或 “out” 参数使用 [Optional] 特性
此检查会报告使用 ref 或 out 声明的可选参数。 调用方可以省略可选实参,但 ref 和 out 参数需要传递实际变量,因此这种组合是无效的。
示例
using System.Runtime.InteropServices;
void Add([Optional] ref object template)
{
}
using System.Runtime.InteropServices;
void Add([Optional] object template)
{
}
如何修复
此检查没有专用的快速修复方案。 移除 ref 或 out ,或将参数设为非可选。
2026年 5月 8日