private void AnalyzeLambdaExpression(SyntaxNodeAnalysisContext context)
        {
            if (GeneratedCodeAnalyzer?.IsGeneratedCode(context) == true)
            {
                return;
            }

            var lambda = (LambdaExpressionSyntax)context.Node;

            if (SimplifyLambdaExpressionRefactoring.CanRefactor(lambda))
            {
                context.ReportDiagnostic(
                    DiagnosticDescriptors.SimplifyLambdaExpression,
                    lambda.Body.GetLocation());

                FadeOut(context, (BlockSyntax)lambda.Body);
            }
        }
Пример #2
0
        private void AnalyzeLambdaExpression(SyntaxNodeAnalysisContext context)
        {
            var lambda = (LambdaExpressionSyntax)context.Node;

            if (SimplifyLambdaExpressionRefactoring.CanRefactor(lambda))
            {
                CSharpSyntaxNode body = lambda.Body;

                context.ReportDiagnostic(DiagnosticDescriptors.SimplifyLambdaExpression, body.GetLocation());

                var block = (BlockSyntax)body;

                context.FadeOutBraces(DiagnosticDescriptors.SimplifyLambdaExpressionFadeOut, block);

                StatementSyntax statement = block.Statements[0];

                if (statement.IsKind(SyntaxKind.ReturnStatement))
                {
                    context.FadeOutToken(DiagnosticDescriptors.SimplifyLambdaExpressionFadeOut, ((ReturnStatementSyntax)statement).ReturnKeyword);
                }
            }
        }