移除無效的全域 'SuppressMessageAttribute' (IDE0076)
財產 | 價值 |
---|---|
規則標識碼 | IDE0076 |
標題 | 移除無效的全域 SuppressMessageAttribute |
類別 | CodeQuality |
子類別 | 其他規則 |
適用的語言 | C# 和 Visual Basic |
概述
此規則會 具有無效 Scope
或 Target
的全域 SuppressMessageAttributes 旗標。 屬性應移除或修正,以參考有效的範圍和目標符號。
選項
此規則沒有相關聯的程式代碼樣式選項。
例
// 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; }
}
}
隱藏警告
如果您想要只隱藏單一違規,請將預處理器指示詞新增至原始程式檔以停用,然後重新啟用規則。
#pragma warning disable IDE0076
// The code that's violating the rule is on this line.
#pragma warning restore IDE0076
若要停用檔案、資料夾或項目的規則,請將其嚴重性設定為 組態檔中的 none
。
[*.{cs,vb}]
dotnet_diagnostic.IDE0076.severity = none
若要停用此整個規則類別,請將類別的嚴重性設定為 組態檔中的 none
。
[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-CodeQuality.severity = none
如需詳細資訊,請參閱 如何在隱藏程式代碼分析警告。