private static bool IsMethodOrderByExtension(InvocationExpressionSyntax invocation, SemanticModel semanticModel) { if (invocation == null) { return(false); } var methodSymbol = semanticModel.GetSymbolInfo(invocation).Symbol as IMethodSymbol; return(methodSymbol != null && methodSymbol.Name == "OrderBy" && methodSymbol.MethodKind == MethodKind.ReducedExtension && CollectionEmptinessChecking.MethodIsOnIEnumerable(methodSymbol, semanticModel)); }
public override void Initialize(AnalysisContext context) { context.RegisterSyntaxNodeActionInNonGenerated( c => { var outerInvocation = (InvocationExpressionSyntax)c.Node; var outerMethodSymbol = c.SemanticModel.GetSymbolInfo(outerInvocation).Symbol as IMethodSymbol; if (outerMethodSymbol == null || !CollectionEmptinessChecking.MethodIsOnIEnumerable(outerMethodSymbol, c.SemanticModel)) { return; } InvocationExpressionSyntax innerInvocation; if (outerMethodSymbol.MethodKind == MethodKind.ReducedExtension) { var memberAccess = outerInvocation.Expression as MemberAccessExpressionSyntax; if (memberAccess == null) { return; } innerInvocation = memberAccess.Expression as InvocationExpressionSyntax; } else { var argument = outerInvocation.ArgumentList.Arguments.FirstOrDefault(); if (argument == null) { return; } innerInvocation = argument.Expression as InvocationExpressionSyntax; } if (innerInvocation == null) { return; } var innerMethodSymbol = c.SemanticModel.GetSymbolInfo(innerInvocation).Symbol as IMethodSymbol; if (innerMethodSymbol == null || !CollectionEmptinessChecking.MethodIsOnIEnumerable(innerMethodSymbol, c.SemanticModel)) { return; } var outerArguments = GetReducedArguments(outerMethodSymbol, outerInvocation); if (CheckForSimplifiable(outerArguments, outerMethodSymbol, innerMethodSymbol, c, innerInvocation)) { return; } if (CheckForCastSimplification(outerMethodSymbol, innerMethodSymbol, innerInvocation, outerInvocation, c)) { return; } }, SyntaxKind.InvocationExpression); }