活动
删除无效的全局 SuppressMessageAttribute (IDE0076)
财产 | 价值 |
---|---|
规则 ID | IDE0076 |
标题 | 删除无效的全局 SuppressMessageAttribute |
类别 | CodeQuality |
子类别 | 其他规则 |
适用的语言 | C# 和 Visual Basic |
此规则标记具有无效 Scope
或 Target
的全局 SuppressMessageAttributes。 应删除或修复该属性以引用有效的作用域和目标符号。
此规则没有关联的代码样式选项。
C#
// IDE0076: Invalid target '~F:N.C.F2' - no matching field named 'F2'
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Category", "Id: Title", Scope = "member", Target = "~F:N.C.F2")]
// IDE0076: Invalid scope 'property'
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Category", "Id: Title", Scope = "property", Target = "~P:N.C.P")]
// Fixed code
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Category", "Id: Title", Scope = "member", Target = "~F:N.C.F")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Category", "Id: Title", Scope = "member", Target = "~P:N.C.P")]
namespace N
{
class C
{
public int F;
public int P { get; }
}
}
如果只想取消单个冲突,请将预处理器指令添加到源文件以禁用,然后重新启用规则。
C#
#pragma warning disable IDE0076
// The code that's violating the rule is on this line.
#pragma warning restore IDE0076
若要禁用文件、文件夹或项目的规则,请将其严重性设置为 配置文件中的 none
。
ini
[*.{cs,vb}]
dotnet_diagnostic.IDE0076.severity = none
若要禁用此整个规则类别,请将类别的严重性设置为 配置文件中的 none
。
ini
[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-CodeQuality.severity = none
有关详细信息,请参阅 如何取消代码分析警告。