public static bool Analyze(SyntaxNodeAnalysisContext context, InvocationExpressionSyntax invocation) { var memberAccess = (MemberAccessExpressionSyntax)invocation.Expression; ExpressionSyntax expression = memberAccess?.Expression; if (expression?.IsKind(SyntaxKind.InvocationExpression) == true) { var invocation2 = (InvocationExpressionSyntax)expression; ArgumentListSyntax argumentList = invocation2.ArgumentList; if (argumentList?.IsMissing == false) { SeparatedSyntaxList <ArgumentSyntax> arguments = argumentList.Arguments; if (arguments.Count == 1 && invocation2.Expression?.IsKind(SyntaxKind.SimpleMemberAccessExpression) == true) { var memberAccess2 = (MemberAccessExpressionSyntax)invocation2.Expression; if (string.Equals(memberAccess2.Name?.Identifier.ValueText, "Where", StringComparison.Ordinal)) { SemanticModel semanticModel = context.SemanticModel; CancellationToken cancellationToken = context.CancellationToken; if (SyntaxAnalyzer.IsEnumerableCastMethod(invocation, semanticModel, cancellationToken) && (SyntaxAnalyzer.IsEnumerableWhereMethod(invocation2, semanticModel, cancellationToken))) { BinaryExpressionSyntax isExpression = GetIsExpression(arguments.First().Expression); if (isExpression != null) { var type = isExpression.Right as TypeSyntax; if (type != null) { TypeSyntax type2 = GetTypeArgument(memberAccess.Name); if (type2 != null) { ITypeSymbol typeSymbol = semanticModel.GetTypeSymbol(type); if (typeSymbol != null) { ITypeSymbol typeSymbol2 = semanticModel.GetTypeSymbol(type2); if (typeSymbol.Equals(typeSymbol2)) { TextSpan span = TextSpan.FromBounds(memberAccess2.Name.Span.Start, invocation.Span.End); if (!invocation.ContainsDirectives(span)) { context.ReportDiagnostic( DiagnosticDescriptors.SimplifyLinqMethodChain, Location.Create(invocation.SyntaxTree, span)); } return(true); } } } } } } } } } } return(false); }