You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you accept that recommendation, you'd need to add the var declaration in the other switch arms as well:
Dictionary<string, (int start, int length)> pathSpans;
var ret = x.o switch {
Expression expr => expr.ToString(TextualTree, out var pathSpans, "C#"),
MemberBinding mbind => mbind.ToString(TextualTree, out var pathSpans, "C#"),
ElementInit init => init.ToString(TextualTree, out var pathSpans, "C#"),
SwitchCase switchCase => switchCase.ToString(TextualTree, out var pathSpans, "C#"),
CatchBlock catchBlock => catchBlock.ToString(TextualTree, out var pathSpans, "C#"),
LabelTarget labelTarget => labelTarget.ToString(TextualTree, out var pathSpans, "C#"),
_ => throw new InvalidOperationException(),
};
I have code like the following:
The analyzer recommends inlining the variable in the first case of the
switch
:but if I do that, the variable isn't available to the other cases in the switch.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: