diff --git a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs index 71e0b82ca010f9784f1963f102d99b6c7a5df6c5..54d637aa56ee9f76ef3d23889ed01da08facf9aa 100644 --- a/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs +++ b/src/EditorFeatures/Core/GoToDefinition/GoToDefinitionHelpers.cs @@ -37,14 +37,14 @@ internal static class GoToDefinitionHelpers // We can't go to the definition of the alias, so use the target type. var solution = project.Solution; - if (symbol is IAliasSymbol) + if (alias != null) { var sourceLocations = NavigableItemFactory.GetPreferredSourceLocations( solution, symbol, cancellationToken); if (sourceLocations.All(l => project.Solution.GetDocument(l.SourceTree) == null)) { - symbol = ((IAliasSymbol)symbol).Target; + symbol = alias.Target; } } @@ -63,9 +63,9 @@ internal static class GoToDefinitionHelpers // If it is a partial method declaration with no body, choose to go to the implementation // that has a method body. - if (symbol is IMethodSymbol) + if (symbol is IMethodSymbol method) { - symbol = ((IMethodSymbol)symbol).PartialImplementationPart ?? symbol; + symbol = method.PartialImplementationPart ?? symbol; } var options = project.Solution.Options; diff --git a/src/EditorFeatures/Core/Implementation/CallHierarchy/CallHierarchyProvider.cs b/src/EditorFeatures/Core/Implementation/CallHierarchy/CallHierarchyProvider.cs index 221db14cc93138cf5396867b1480a663da9aac4b..a6fe549c14dab4626fe64ebc395dd54320ab7cb7 100644 --- a/src/EditorFeatures/Core/Implementation/CallHierarchy/CallHierarchyProvider.cs +++ b/src/EditorFeatures/Core/Implementation/CallHierarchy/CallHierarchyProvider.cs @@ -61,11 +61,10 @@ internal partial class CallHierarchyProvider private ISymbol GetTargetSymbol(ISymbol symbol) { - if (symbol is IMethodSymbol) + if (symbol is IMethodSymbol methodSymbol) { - var methodSymbol = (IMethodSymbol)symbol; - methodSymbol = methodSymbol.ReducedFrom != null ? methodSymbol.ReducedFrom : methodSymbol; - methodSymbol = methodSymbol.ConstructedFrom != null ? methodSymbol.ConstructedFrom : methodSymbol; + methodSymbol = methodSymbol.ReducedFrom ?? methodSymbol; + methodSymbol = methodSymbol.ConstructedFrom ?? methodSymbol; return methodSymbol; } diff --git a/src/EditorFeatures/Core/Implementation/Formatting/FormatCommandHandler.cs b/src/EditorFeatures/Core/Implementation/Formatting/FormatCommandHandler.cs index 68a89e4b44cb13157ac01ecc3e5eeb3761e23d84..6af99f9605c5d6eedaa6839c953db2e6ca1cd2d0 100644 --- a/src/EditorFeatures/Core/Implementation/Formatting/FormatCommandHandler.cs +++ b/src/EditorFeatures/Core/Implementation/Formatting/FormatCommandHandler.cs @@ -135,9 +135,9 @@ public void ExecuteReturnOrTypeCommand(CommandArgs args, Action nextHandler, Can return; } } - else if (args is TypeCharCommandArgs) + else if (args is TypeCharCommandArgs typeCharArgs) { - var typedChar = ((TypeCharCommandArgs)args).TypedChar; + var typedChar = typeCharArgs.TypedChar; if (!service.SupportsFormattingOnTypedCharacter(document, typedChar) || !TryFormat(textView, document, service, typedChar, caretPositionMarker, formatOnReturn: false, cancellationToken: cancellationToken)) { diff --git a/src/EditorFeatures/Core/Implementation/IntelliSense/ViewTextSpan.cs b/src/EditorFeatures/Core/Implementation/IntelliSense/ViewTextSpan.cs index fa61f94d73129d92c6acc24db6cdffd1ad6f7afa..40e23f668d5137101452a908a72430f0140c151f 100644 --- a/src/EditorFeatures/Core/Implementation/IntelliSense/ViewTextSpan.cs +++ b/src/EditorFeatures/Core/Implementation/IntelliSense/ViewTextSpan.cs @@ -100,9 +100,8 @@ private static IEnumerable MapUpToSnapshotRecursive(SnapshotSpan start, IP yield return result; } } - else if (source is IProjectionSnapshot) + else if (source is IProjectionSnapshot sourceProjection) { - var sourceProjection = source as IProjectionSnapshot; foreach (var span in MapUpToSnapshotRecursive(start, sourceProjection)) { foreach (var result in target.MapFromSourceSnapshot(new SnapshotSpan(source, span))) diff --git a/src/EditorFeatures/Core/Implementation/KeywordHighlighting/AbstractKeywordHighlighter.cs b/src/EditorFeatures/Core/Implementation/KeywordHighlighting/AbstractKeywordHighlighter.cs index 9aa3b811015ef924e5c7e83669afc77d0636ea66..db73c50e5314ca1a824f33528f655b1a35f9f0c2 100644 --- a/src/EditorFeatures/Core/Implementation/KeywordHighlighting/AbstractKeywordHighlighter.cs +++ b/src/EditorFeatures/Core/Implementation/KeywordHighlighting/AbstractKeywordHighlighter.cs @@ -18,9 +18,9 @@ internal abstract class AbstractKeywordHighlighter : IHighlighter { for (var parent = token.Parent; parent != null; parent = parent.Parent) { - if (parent is TNode) + if (parent is TNode parentTNode) { - var highlights = GetHighlights((TNode)parent, cancellationToken); + var highlights = GetHighlights(parentTNode, cancellationToken); // Only return them if any of them matched if (highlights.Any(span => span.IntersectsWith(position)))