提交 6db545eb 编写于 作者: C Cyrus Najmabadi

Use pattern matching in a few more places.

上级 9da4a909
......@@ -507,7 +507,7 @@ private ConsList<TypeSymbol> GetBasesBeingResolved(TypeSyntax expression)
for (; expression != null && expression.Parent != null; expression = expression.Parent as TypeSyntax)
{
var parent = expression.Parent;
if (parent is BaseTypeSyntax && parent.Parent != null && parent.Parent.Kind() == SyntaxKind.BaseList && ((BaseTypeSyntax)parent).Type == expression)
if (parent is BaseTypeSyntax baseType && parent.Parent != null && parent.Parent.Kind() == SyntaxKind.BaseList && baseType.Type == expression)
{
// we have a winner
var decl = (BaseTypeDeclarationSyntax)parent.Parent.Parent;
......
......@@ -140,10 +140,10 @@ private void DumpSymbol(Symbol sym, StringBuilder builder, int level)
throw new InvalidOperationException("Unexpected symbol kind");
}
if (sym is NamespaceOrTypeSymbol && ((NamespaceOrTypeSymbol)sym).GetMembers().Any())
if (sym is NamespaceOrTypeSymbol namespaceOrType && namespaceOrType.GetMembers().Any())
{
builder.AppendLine(" { ");
var q = from c in ((NamespaceOrTypeSymbol)sym).GetMembers()
var q = from c in namespaceOrType.GetMembers()
orderby c.Name
select c;
......
......@@ -194,7 +194,7 @@ public static ConstantValue GetSymConstantValue(ITypeSymbol type, object symValu
return ConstantValue.Create((double)symValue);
case SpecialType.System_String:
if (symValue is int && (int)symValue == 0)
if (symValue is int intVal1 && intVal1 == 0)
{
return ConstantValue.Null;
}
......@@ -204,8 +204,7 @@ public static ConstantValue GetSymConstantValue(ITypeSymbol type, object symValu
return ConstantValue.Create(string.Empty);
}
var str = symValue as string;
if (str == null)
if (!(symValue is string str))
{
return ConstantValue.Bad;
}
......@@ -213,7 +212,7 @@ public static ConstantValue GetSymConstantValue(ITypeSymbol type, object symValu
return ConstantValue.Create(str);
case SpecialType.System_Object:
if (symValue is int && (int)symValue == 0)
if (symValue is int intVal2 && intVal2 == 0)
{
return ConstantValue.Null;
}
......@@ -221,12 +220,12 @@ public static ConstantValue GetSymConstantValue(ITypeSymbol type, object symValu
return ConstantValue.Bad;
case SpecialType.System_Decimal:
if (!(symValue is decimal))
if (!(symValue is decimal decimalValue))
{
return ConstantValue.Bad;
}
return ConstantValue.Create((decimal)symValue);
return ConstantValue.Create(decimalValue);
case SpecialType.System_DateTime:
if (!(symValue is double))
......@@ -239,7 +238,7 @@ public static ConstantValue GetSymConstantValue(ITypeSymbol type, object symValu
case SpecialType.None:
if (type.IsReferenceType)
{
if (symValue is int && (int)symValue == 0)
if (symValue is int intValue3 && intValue3 == 0)
{
return ConstantValue.Null;
}
......
......@@ -174,7 +174,7 @@ protected override HashSet<string> GetInitializedMembers(SyntaxTree tree, int po
protected override bool IsInitializable(ISymbol member, INamedTypeSymbol containingType)
{
if (member is IPropertySymbol && ((IPropertySymbol)member).Parameters.Any(p => !p.IsOptional))
if (member is IPropertySymbol property && property.Parameters.Any(p => !p.IsOptional))
{
return false;
}
......
......@@ -163,7 +163,7 @@ private bool TryGetTextForSymbol(SyntaxToken token, SemanticModel semanticModel,
}
// Just use syntaxfacts for operators
if (symbol is IMethodSymbol && ((IMethodSymbol)symbol).MethodKind == MethodKind.BuiltinOperator)
if (symbol is IMethodSymbol method && method.MethodKind == MethodKind.BuiltinOperator)
{
text = null;
return false;
......
......@@ -744,10 +744,10 @@ public override Task<ImmutableArray<Project>> DetermineProjectsToSearchAsync(ISy
FindReferencesSearchOptions options, CancellationToken cancellationToken)
{
var symbol = symbolAndProjectId.Symbol;
if (symbol is TSymbol && CanFind((TSymbol)symbol))
if (symbol is TSymbol typedSymbol && CanFind(typedSymbol))
{
return DetermineCascadedSymbolsAsync(
symbolAndProjectId.WithSymbol((TSymbol)symbol),
symbolAndProjectId.WithSymbol(typedSymbol),
solution, projects, options, cancellationToken);
}
......
......@@ -211,7 +211,7 @@ private SyntaxNode GetContainer(SemanticModel semanticModel, SyntaxNode paramete
{
var declaredSymbol = semanticModel.GetDeclaredSymbol(current);
if (declaredSymbol is IMethodSymbol && ((IMethodSymbol)declaredSymbol).MethodKind != MethodKind.AnonymousFunction)
if (declaredSymbol is IMethodSymbol method && method.MethodKind != MethodKind.AnonymousFunction)
{
return current;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册