TypeName | SA1142ReferToTupleElementsByName |
CheckId | SA1142 |
Category | Readability Rules |
📝 This rule is new for StyleCop Analyzers, and was not present in StyleCop Classic. 📝 This rule is only active for C# 7.0 and higher
An element of a tuple was referenced by its metadata name when an element name is available.
An element of a tuple was referenced by its metadata name when an element name is available. See the documentation on tuple types for information on how to work with tuples in C# 7.
For example, the following code would produce a violation of this rule:
(int valueA, int valueB) x;
var y = x.Item1; // SA1142
The following code would not produce any violations:
(int valueA, int valueB) x;
var y = x.valueA;
To fix a violation of this rule, use the appropriate tuple element name in code instead of the metadata name.
[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1142:ReferToTupleElementsByName", Justification = "Reviewed.")]
#pragma warning disable SA1142 // Refer to tuple elements by name
#pragma warning restore SA1142 // Refer to tuple elements by name