private static void CheckForIsAssignableFrom(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocation, MemberAccessExpressionSyntax memberAccess, IMethodSymbol methodSymbol, ExpressionSyntax argument) { if (methodSymbol.Name != "IsAssignableFrom" || !TypeExaminationOnSystemType.IsGetTypeCall(argument as InvocationExpressionSyntax, context.SemanticModel)) { return; } if (memberAccess.Expression is TypeOfExpressionSyntax) { context.ReportDiagnostic(Diagnostic.Create(Rule, invocation.GetLocation(), ImmutableDictionary <string, string> .Empty .Add(UseIsOperatorKey, true.ToString()) .Add(ShouldRemoveGetType, true.ToString()), MessageIsOperator)); } else { context.ReportDiagnostic(Diagnostic.Create(Rule, invocation.GetLocation(), ImmutableDictionary <string, string> .Empty .Add(UseIsOperatorKey, false.ToString()) .Add(ShouldRemoveGetType, true.ToString()), MessageIsInstanceOfType)); } }
private static void CheckGetTypeAndTypeOfEquality(ExpressionSyntax sideA, ExpressionSyntax sideB, Location location, SyntaxNodeAnalysisContext context) { if (!TypeExaminationOnSystemType.IsGetTypeCall(sideA as InvocationExpressionSyntax, context.SemanticModel)) { return; } var typeSyntax = (sideB as TypeOfExpressionSyntax)?.Type; if (typeSyntax == null) { return; } var typeSymbol = context.SemanticModel.GetTypeInfo(typeSyntax).Type; if (typeSymbol == null || !typeSymbol.IsSealed || typeSymbol.OriginalDefinition.Is(KnownType.System_Nullable_T)) { return; } context.ReportDiagnostic(Diagnostic.Create(Rule, location, MessageIsOperator)); }