代码检查:多余的 [AttributeUsage] 属性属性赋值
当赋值是多余时,此检查会报告 [AttributeUsage(...)] 内的属性赋值。 这通常发生在赋值本身就是默认值的情况下,或者像 Inherited 这样的属性对所选的属性目标没有意义时。
示例
using System;
[AttributeUsage(AttributeTargets.Method, Inherited = true)]
sealed class MyAttribute : Attribute
{
}
using System;
[AttributeUsage(AttributeTargets.Method)]
sealed class MyAttribute : Attribute
{
}
快速修复
该修复在保持属性行为不变的同时,去除了声明中的不必要内容。
2026年 5月 8日