Пример #1
0
        public static void Analyze(SyntaxNodeAnalysisContext context, PrefixUnaryExpressionSyntax logicalNot)
        {
            ExpressionSyntax operand = logicalNot.Operand;

            switch (operand?.Kind())
            {
            case SyntaxKind.TrueLiteralExpression:
            case SyntaxKind.FalseLiteralExpression:
            {
                context.ReportDiagnostic(DiagnosticDescriptors.SimplifyLogicalNotExpression, logicalNot.GetLocation());
                break;
            }

            case SyntaxKind.LogicalNotExpression:
            {
                var innerLogicalNot = (PrefixUnaryExpressionSyntax)operand;

                TextSpan span     = TextSpan.FromBounds(logicalNot.OperatorToken.Span.Start, innerLogicalNot.OperatorToken.Span.End);
                Location location = Location.Create(logicalNot.SyntaxTree, span);

                context.ReportDiagnostic(DiagnosticDescriptors.SimplifyLogicalNotExpression, location);
                break;
            }
            }
        }