使用显式提供的元组名称 (IDE0033)

财产 价值
规则 ID IDE0033
标题 使用显式提供的元组名称
类别 样式
子类别 语言规则(表达式级首选项)
适用的语言 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, int) 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 (String, 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

有关详细信息,请参阅 如何取消代码分析警告

另请参阅