diff --git a/src/Ramstack.ExpressionParser/ExpressionBuilder.Helpers.cs b/src/Ramstack.ExpressionParser/ExpressionBuilder.Helpers.cs index 93ae29f..7f4fb6f 100644 --- a/src/Ramstack.ExpressionParser/ExpressionBuilder.Helpers.cs +++ b/src/Ramstack.ExpressionParser/ExpressionBuilder.Helpers.cs @@ -233,13 +233,8 @@ private static BinaryExpression ApplyNullCoalescing(Identifier op, Expression lh /// /// if the expression is the null literal; otherwise, . /// - private static bool IsNullLiteral(Expr expr) - { - while (expr is Expr.Parenthesized parenthesized) - expr = parenthesized.Expression; - - return expr is Expr.Literal { Value: null }; - } + private static bool IsNullLiteral(Expr expr) => + SkipParentheses(expr) is Expr.Literal { Value: null }; /// /// Determines whether the specified expression is the integer literal 0, possibly in parentheses. @@ -248,12 +243,22 @@ private static bool IsNullLiteral(Expr expr) /// /// if the expression is the integer literal 0; otherwise, . /// - private static bool IsZeroLiteral(Expr expr) + private static bool IsZeroLiteral(Expr expr) => + SkipParentheses(expr) is Expr.Literal { Value: 0 or 0u or 0L or 0UL }; + + /// + /// Removes any number of enclosing parentheses from the specified expression. + /// + /// The expression to unwrap. + /// + /// The expression without enclosing parentheses, or if it is not in parentheses. + /// + private static Expr SkipParentheses(Expr expr) { while (expr is Expr.Parenthesized parenthesized) expr = parenthesized.Expression; - return expr is Expr.Literal { Value: 0 or 0u or 0L or 0UL }; + return expr; } ///