提交 b73e9dd2 编写于 作者: C CyrusNajmabadi

Use pattern matching.

上级 8b48428e
......@@ -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;
......
......@@ -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;
}
......
......@@ -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))
{
......
......@@ -100,9 +100,8 @@ private static IEnumerable<Span> 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)))
......
......@@ -18,9 +18,9 @@ internal abstract class AbstractKeywordHighlighter<TNode> : 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)))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册