自動実装プロパティを使用する (IDE0032)

プロパティ
ルール ID IDE0032
Title 自動実装プロパティを使用する
カテゴリ スタイル
Subcategory 言語規則 (式レベル基本設定)
該当言語 C# および Visual Basic
導入されたバージョン Visual Studio 2017
[オプション] dotnet_style_prefer_auto_properties

概要

このスタイル規則は、自動実装プロパティとプライベート バッキング フィールドを持つプロパティの使用に関するものです。

オプション

オプションでは、規則を適用する動作を指定します。 オプションの構成の詳細については、「オプションの書式」を参照してください。

dotnet_style_prefer_auto_properties

プロパティ 説明
オプション名 dotnet_style_prefer_auto_properties
オプションの値 true 自動実装プロパティを使用します
false プライベート バッキング フィールドを持つプロパティを使用します
既定のオプションの値 true
// dotnet_style_prefer_auto_properties = true
public int Age { get; }

// dotnet_style_prefer_auto_properties = false
private int age;

public int Age
{
    get
    {
        return age;
    }
}
' dotnet_style_prefer_auto_properties = true
Public ReadOnly Property Age As Integer

' dotnet_style_prefer_auto_properties = false
Private _age As Integer

Public ReadOnly Property Age As Integer
    Get
        return _age
    End Get
End Property

警告を抑制する

単一の違反だけを抑制する場合は、ソース ファイルにプリプロセッサ ディレクティブを追加して無効にしてから、規則を再度有効にします。

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

ファイル、フォルダー、またはプロジェクトのルールを無効にするには、構成ファイルでその重要度を none に設定します。

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

すべてのコード スタイル規則を無効にするには、構成ファイルでカテゴリ Style の重要度を none に設定します。

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

詳細については、「コード分析の警告を抑制する方法」を参照してください。

関連項目