提交 e7080140 编写于 作者: C Cyrus Najmabadi

Use switch expressoin

上级 0d027cee
......@@ -308,16 +308,13 @@ private async Task<WrappingGroup> GetWrapEveryGroupAsync()
}
private string GetNestedCodeActionTitle(WrappingStyle wrappingStyle)
{
switch (wrappingStyle)
=> wrappingStyle switch
{
case WrappingStyle.WrapFirst_IndentRest: return Wrapper.Indent_all_items;
case WrappingStyle.UnwrapFirst_AlignRest: return Wrapper.Align_wrapped_items;
case WrappingStyle.UnwrapFirst_IndentRest: return Wrapper.Indent_wrapped_items;
default:
throw ExceptionUtilities.UnexpectedValue(wrappingStyle);
}
}
WrappingStyle.WrapFirst_IndentRest => Wrapper.Indent_all_items,
WrappingStyle.UnwrapFirst_AlignRest => Wrapper.Align_wrapped_items,
WrappingStyle.UnwrapFirst_IndentRest => Wrapper.Indent_wrapped_items,
_ => throw ExceptionUtilities.UnexpectedValue(wrappingStyle),
};
private ImmutableArray<Edit> GetWrapEachEdits(
WrappingStyle wrappingStyle, SyntaxTrivia indentationTrivia)
......
......@@ -143,15 +143,12 @@ public override string Title
public override string EquivalenceKey => _equivalenceKey;
private static string GetDescription(ISymbol throughMember)
{
switch (throughMember)
=> throughMember switch
{
case IFieldSymbol field: return field.Name;
case IPropertySymbol property: return property.Name;
default:
throw new InvalidOperationException();
}
}
IFieldSymbol field => field.Name,
IPropertySymbol property => property.Name,
_ => throw new InvalidOperationException(),
};
protected override Task<Document> GetChangedDocumentAsync(CancellationToken cancellationToken)
{
......
......@@ -121,15 +121,12 @@ private object CreateAndStartScope(LogType kind, FunctionId functionId)
// TelemetryScope<Operation> can't be shared
var eventName = functionId.GetEventName();
switch (kind)
return kind switch
{
case LogType.Trace:
return _session.StartOperation(eventName);
case LogType.UserAction:
return _session.StartUserTask(eventName);
default:
return FatalError.Report(new Exception($"unknown type: {kind}"));
}
LogType.Trace => _session.StartOperation(eventName),
LogType.UserAction => _session.StartUserTask(eventName),
_ => (object)FatalError.Report(new Exception($"unknown type: {kind}")),
};
}
private TelemetryEvent CreateTelemetryEvent(FunctionId functionId, KeyValueLogMessage logMessage)
......
......@@ -136,23 +136,15 @@ private void AppendLeafTag(string name)
}
private static string GetBinaryOperatorKindText(BinaryOperatorKind kind)
{
switch (kind)
=> kind switch
{
case BinaryOperatorKind.Plus:
return "plus";
case BinaryOperatorKind.BitwiseOr:
return "bitor";
case BinaryOperatorKind.BitwiseAnd:
return "bitand";
case BinaryOperatorKind.Concatenate:
return "concatenate";
case BinaryOperatorKind.AddDelegate:
return "adddelegate";
default:
throw new InvalidOperationException("Invalid BinaryOperatorKind: " + kind.ToString());
}
}
BinaryOperatorKind.Plus => "plus",
BinaryOperatorKind.BitwiseOr => "bitor",
BinaryOperatorKind.BitwiseAnd => "bitand",
BinaryOperatorKind.Concatenate => "concatenate",
BinaryOperatorKind.AddDelegate => "adddelegate",
_ => throw new InvalidOperationException("Invalid BinaryOperatorKind: " + kind.ToString()),
};
private static string GetVariableKindText(VariableKind kind)
=> kind switch
......
......@@ -2761,34 +2761,22 @@ private static AccessorListSyntax GetAccessorList(SyntaxNode declaration)
};
private static bool CanHaveAccessors(SyntaxNode declaration)
{
switch (declaration.Kind())
=> declaration.Kind() switch
{
case SyntaxKind.PropertyDeclaration:
return ((PropertyDeclarationSyntax)declaration).ExpressionBody == null;
case SyntaxKind.IndexerDeclaration:
return ((IndexerDeclarationSyntax)declaration).ExpressionBody == null;
case SyntaxKind.EventDeclaration:
return true;
default:
return false;
}
}
SyntaxKind.PropertyDeclaration => ((PropertyDeclarationSyntax)declaration).ExpressionBody == null,
SyntaxKind.IndexerDeclaration => ((IndexerDeclarationSyntax)declaration).ExpressionBody == null,
SyntaxKind.EventDeclaration => true,
_ => false,
};
private static SyntaxNode WithAccessorList(SyntaxNode declaration, AccessorListSyntax accessorList)
{
switch (declaration.Kind())
=> declaration.Kind() switch
{
case SyntaxKind.PropertyDeclaration:
return ((PropertyDeclarationSyntax)declaration).WithAccessorList(accessorList);
case SyntaxKind.IndexerDeclaration:
return ((PropertyDeclarationSyntax)declaration).WithAccessorList(accessorList);
case SyntaxKind.EventDeclaration:
return ((EventDeclarationSyntax)declaration).WithAccessorList(accessorList);
default:
return declaration;
}
}
SyntaxKind.PropertyDeclaration => ((PropertyDeclarationSyntax)declaration).WithAccessorList(accessorList),
SyntaxKind.IndexerDeclaration => ((PropertyDeclarationSyntax)declaration).WithAccessorList(accessorList),
SyntaxKind.EventDeclaration => ((EventDeclarationSyntax)declaration).WithAccessorList(accessorList),
_ => declaration,
};
private static AccessorListSyntax AsAccessorList(IEnumerable<SyntaxNode> nodes, SyntaxKind parentKind)
{
......
......@@ -65,19 +65,13 @@ private void AddInitializerSuppressOperations(List<SuppressOperation> list, Synt
}
private InitializerExpressionSyntax GetInitializerNode(SyntaxNode node)
{
switch (node)
=> node switch
{
case ObjectCreationExpressionSyntax objectCreationNode:
return objectCreationNode.Initializer;
case ArrayCreationExpressionSyntax arrayCreationNode:
return arrayCreationNode.Initializer;
case ImplicitArrayCreationExpressionSyntax implicitArrayNode:
return implicitArrayNode.Initializer;
}
return null;
}
ObjectCreationExpressionSyntax objectCreationNode => objectCreationNode.Initializer,
ArrayCreationExpressionSyntax arrayCreationNode => arrayCreationNode.Initializer,
ImplicitArrayCreationExpressionSyntax implicitArrayNode => implicitArrayNode.Initializer,
_ => null,
};
private SyntaxToken? GetLastTokenOfType(SyntaxNode node)
{
......
......@@ -536,26 +536,15 @@ private bool FirstLineBlank()
// next trivia is moved to next line or already on a new line, use indentation
if (rule.Lines > 0 || lineColumnAfterExistingWhitespace.WhitespaceOnly)
{
switch (rule.IndentationOperation)
return rule.IndentationOperation switch
{
case LineColumnRule.IndentationOperations.Absolute:
return Math.Max(0, rule.Indentation);
case LineColumnRule.IndentationOperations.Default:
return this.Context.GetBaseIndentation(trivia2.RawKind == 0 ? this.EndPosition : trivia2.SpanStart);
case LineColumnRule.IndentationOperations.Given:
return (trivia2.RawKind == 0) ? this.Spaces : Math.Max(0, _indentation);
case LineColumnRule.IndentationOperations.Follow:
return Math.Max(0, lineColumnBeforeTrivia1.Column);
case LineColumnRule.IndentationOperations.Preserve:
return existingWhitespaceBetween.Spaces;
default:
throw ExceptionUtilities.UnexpectedValue(rule.IndentationOperation);
}
LineColumnRule.IndentationOperations.Absolute => Math.Max(0, rule.Indentation),
LineColumnRule.IndentationOperations.Default => this.Context.GetBaseIndentation(trivia2.RawKind == 0 ? this.EndPosition : trivia2.SpanStart),
LineColumnRule.IndentationOperations.Given => (trivia2.RawKind == 0) ? this.Spaces : Math.Max(0, _indentation),
LineColumnRule.IndentationOperations.Follow => Math.Max(0, lineColumnBeforeTrivia1.Column),
LineColumnRule.IndentationOperations.Preserve => existingWhitespaceBetween.Spaces,
_ => throw ExceptionUtilities.UnexpectedValue(rule.IndentationOperation),
};
}
// okay, we are not on a its own line, use space information
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册