使用複合指派(IDE0054和IDE0074)
本文說明兩個相關規則,IDE0054
和 IDE0074
。
財產 | 價值 |
---|---|
規則標識碼 | IDE0054 |
標題 | 使用複合指派 |
類別 | 風格 |
子類別 | 語言規則(語言表達層級偏好) |
適用的語言 | C# 和 Visual Basic |
選項 | dotnet_style_prefer_compound_assignment |
財產 | 價值 |
---|---|
規則標識碼 | IDE0074 |
標題 | 使用聯合複合指派 |
類別 | 風格 |
子類別 | 語言規則 (表達層級偏好) |
適用的語言 | C# 和 Visual Basic |
選項 | dotnet_style_prefer_compound_assignment |
概述
這些規則涉及 複合指派的使用。
IDE0074
用於合併複合賦值運算的報告,而 IDE0054
則用於其他複合賦值運算的報告。
選項
選項值會指定是否需要複合指派。
如需設定選項的相關資訊,請參閱 選項格式。
dotnet_style_prefer_compound_assignment(偏好使用複合賦值運算)
財產 | 價值 | 描述 |
---|---|---|
選項名稱 | dotnet_style_prefer_compound_assignment | |
選項值 | true |
偏好複合指派表達式 |
false |
不要偏好複合指派表達式 | |
預設選項值 | true |
// dotnet_style_prefer_compound_assignment = true
x += 5;
// dotnet_style_prefer_compound_assignment = false
x = x + 5;
' dotnet_style_prefer_compound_assignment = true
x += 5
' dotnet_style_prefer_compound_assignment = false
x = x + 5
隱藏警告
如果您想要只隱藏單一違規,請將預處理器指示詞新增至原始程式檔以停用,然後重新啟用規則。
#pragma warning disable IDE0054 // Or IDE0074
// The code that's violating the rule is on this line.
#pragma warning restore IDE0054 // Or IDE0074
若要停用檔案、資料夾或項目的規則,請將其嚴重性設定為 組態檔中的 none
。
[*.{cs,vb}]
dotnet_diagnostic.IDE0054.severity = none
dotnet_diagnostic.IDE0074.severity = none
若要停用所有程式碼樣式規則,請將類別 Style
的嚴重性設定為 組態檔中的 none
。
[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Style.severity = none
如需詳細資訊,請參閱 如何在隱藏程式代碼分析警告。