共用方式為


條件運算式權杖 (IDE2005) 之後不允許空白行

房產 價值觀
規則識別碼 IDE2005
標題 條件運算式權杖後不允許空白行
類別 Style
子類別 語言規則 (換行偏好設定)
適用語言 C#
Options csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental

備註

此規則是實驗性的,可能會變更或刪除。

概觀

此樣式規則會強制條件式 (三元) 運算式中的問號 (?) 或冒號 (:) 記號之後不應有空行。 這些運算子後面應該緊接其各自的運算式,不得有空行。

選項

選項指定您希望規則強制執行的行為。 如需設定選項的相關資訊,請參閱 選項格式

csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental

房產 價值觀 Description
選項名稱 csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental
選項值 true 允許條件式中權杖後面有空行
false Require 陳述式以立即遵循條件式中的權杖
預設選項值 true

Example

// csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true
int result = IsTrue ?
    ComplexExpr1() :
    ComplexExpr2();
// csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = false
int result = IsTrue
    ? ComplexExpr1()
    : ComplexExpr2();

隱藏警告

如果您只想隱藏單一違規,請將前置處理器指示詞新增至來源檔案以停用,然後重新啟用規則。

#pragma warning disable IDE2005
// The code that's violating the rule is on this line.
#pragma warning restore IDE2005

若要停用檔案、資料夾或專案的規則,請在組態檔中將其嚴重性設定為 。none

[*.{cs,vb}]
dotnet_diagnostic.IDE2005.severity = none

若要停用所有程式碼樣式規則,請在組態檔中將類別Style的嚴重性設定為。none

[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-style.severity = none

如需詳細資訊,請參閱 如何隱藏程式碼分析警告

另請參閱