Ejemplo n.º 1
0
        internal SyntaxNode Negate(
            SyntaxNode expression,
            SyntaxGenerator generator,
            ISyntaxFactsService syntaxFacts,
            SemanticModel semanticModel,
            CancellationToken cancellationToken)
        {
            if (syntaxFacts.IsParenthesizedExpression(expression))
            {
                return(syntaxFacts.Parenthesize(
                           Negate(
                               syntaxFacts.GetExpressionOfParenthesizedExpression(expression),
                               generator,
                               syntaxFacts,
                               semanticModel,
                               cancellationToken))
                       .WithTriviaFrom(expression));
            }
            if (syntaxFacts.IsBinaryExpression(expression))
            {
                return(GetNegationOfBinaryExpression(expression, generator, syntaxFacts, semanticModel, cancellationToken));
            }
            else if (syntaxFacts.IsLiteralExpression(expression))
            {
                return(GetNegationOfLiteralExpression(expression, generator, semanticModel));
            }
            else if (syntaxFacts.IsLogicalNotExpression(expression))
            {
                return(GetNegationOfLogicalNotExpression(expression, syntaxFacts));
            }

            return(generator.LogicalNotExpression(expression));
        }