-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prefer ValueTuple over Tuple #33791
Comments
Estimates:
|
@terrajobst when would it be beneficial to use a At first glance, I think the estimates are both Small (Analyzer and Fixer). The Docs specify the differences between a |
Two reasons: |
|
@terrajobst @dsyme thanks for the input. Are there any other restrictions we should know about when using |
[Triage note]: The analyzer should suggest using
I wonder how the fixer should work and if we should suggest a code fix:
public class Test
{
private Tuple<int, string> _field;
public void M()
{
Tuple<int, string> t = GetTuple();
if (t == null)
{
Console.WriteLine(t.Item1);
}
if (t == _field)
{
Console.WriteLine(GetString(f));
}
}
internal Tuple<int, string> GetTuple() => new Tuple<int, string>(1, "id");
internal string GetString(Tuple<int, string> args) => args.Item2;
} |
Generally seems like a good idea. A concern was raised about potentially limiting this to 5-tuples or smaller (or any other arbitrary number), but we don't feel that's important. One diagnostic ID should be used for member bodies and for member signatures. By default the analyzer should not report on "exposed" API (e.g. public, protected), but it would be appropriate to have a configuration parameter to allow opting in to exposed API. For the fixer, we identified a concern around type coercion (e.g. Category: Performance |
The rule should find and flag cases where a
Tuple<...>
is being used but where aValueTuple<...>
would suffice, ideally with the C# language syntax employed. There are some cases where aTuple<...>
is beneficial, however, so the patterns identified here would be constrained.Category: Performance
Severity: Info
The text was updated successfully, but these errors were encountered: