Rediģēt

Kopīgot, izmantojot


Use explicitly provided tuple name (IDE0033)

Property Value
Rule ID IDE0033
Title Use explicitly provided tuple name
Category Style
Subcategory Language rules (expression-level preferences)
Applicable languages C# and Visual Basic
Options dotnet_style_explicit_tuple_names

Overview

This style rule concerns the use of explicit tuple names versus implicit 'ItemX' properties when accessing tuple fields.

Options

Options specify the behavior that you want the rule to enforce. For information about configuring options, see Option format.

dotnet_style_explicit_tuple_names

Property Value Description
Option name dotnet_style_explicit_tuple_names
Option values true Prefer tuple names to ItemX properties
false Prefer ItemX properties to tuple names
Default option value 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

Suppress a warning

If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

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

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

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

To disable all of the code-style rules, set the severity for the category Style to none in the configuration file.

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

For more information, see How to suppress code analysis warnings.

See also