明示的に提供されたタプル名を使用する (IDE0033)

プロパティ
ルール ID IDE0033
Title 明示的に提供されたタプル名を使用する
カテゴリ スタイル
Subcategory 言語規則 (式レベル基本設定)
該当言語 C# および Visual Basic
[オプション] dotnet_style_explicit_tuple_names

概要

このスタイル規則は、タプル フィールドにアクセスするときに、明示的なタプル名と、暗黙的な "ItemX" プロパティのどちらを使用するかに関するものです。

オプション

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

dotnet_style_explicit_tuple_names

プロパティ 説明
オプション名 dotnet_style_explicit_tuple_names
オプションの値 true ItemX プロパティではなくタプル名を使用します
false タプル名ではなく ItemX プロパティを使用します
既定のオプションの値 true
// dotnet_style_explicit_tuple_names = true
(string name, int age) customer = GetCustomer();
var name = customer.name;

// dotnet_style_explicit_tuple_names = false
(string name, int age) customer = GetCustomer();
var name = customer.Item1;
 ' dotnet_style_explicit_tuple_names = true
Dim customer As (name As String, age As Integer) = GetCustomer()
Dim name = customer.name

' dotnet_style_explicit_tuple_names = false
Dim customer As (name As String, age As Integer) = GetCustomer()
Dim name = customer.Item1

警告を抑制する

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

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

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

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

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

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

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

こちらもご覧ください