From 204c331c365d925b58fc53b3a92ec7b561472c49 Mon Sep 17 00:00:00 2001 From: Allison Chou Date: Wed, 23 Sep 2020 15:15:28 -0700 Subject: [PATCH] Cleanup --- .../AbstractAddParameterCodeFixProvider.cs | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/Features/Core/Portable/AddParameter/AbstractAddParameterCodeFixProvider.cs b/src/Features/Core/Portable/AddParameter/AbstractAddParameterCodeFixProvider.cs index 6c5665c0de3..96a83511489 100644 --- a/src/Features/Core/Portable/AddParameter/AbstractAddParameterCodeFixProvider.cs +++ b/src/Features/Core/Portable/AddParameter/AbstractAddParameterCodeFixProvider.cs @@ -140,26 +140,21 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context) { // Not supported if this is "new { ... }" (as there are no parameters at all. - var typeNode = syntaxFacts.IsImplicitObjectCreationExpression(node) ? - node : syntaxFacts.GetObjectCreationType(objectCreation); + var typeNode = syntaxFacts.IsImplicitObjectCreationExpression(node) + ? node + : syntaxFacts.GetObjectCreationType(objectCreation); if (typeNode == null) { return new RegisterFixData(); } - INamedTypeSymbol type = null; var symbol = semanticModel.GetSymbolInfo(typeNode, cancellationToken).GetAnySymbol(); - - // Implicit object creation expressions - if (symbol is IMethodSymbol methodSymbol) - { - type = methodSymbol.ContainingType; - } - // Regular object creation expressions - else if (symbol is INamedTypeSymbol namedTypeSymbol) + var type = symbol switch { - type = namedTypeSymbol; - } + IMethodSymbol methodSymbol => methodSymbol.ContainingType, // Implicit object creation expressions + INamedTypeSymbol namedTypeSymbol => namedTypeSymbol, // Standard object creation expressions + _ => null, + }; // If we can't figure out the type being created, or the type isn't in source, // then there's nothing we can do. -- GitLab