/// <summary> /// Outputs a given expression tree to a string. /// </summary> /// <param name="node">The expression node.</param> /// <returns>The string representing the expression.</returns> public static new string ExpressionToString(Expression node) { node.CheckNotNull(nameof(node)); ObjectExpressionStringBuilder expressionStringBuilder = new ObjectExpressionStringBuilder(); expressionStringBuilder.Visit(node); string result = expressionStringBuilder.ToString(); result = TrimBrackets(result); if (expressionStringBuilder.operatorAndCount > 0 && expressionStringBuilder.operatorElseCount == 0) { return(NormalizeBrackets(result, "&&")); } else if (expressionStringBuilder.operatorAndCount == 0 && expressionStringBuilder.operatorElseCount > 0) { return(NormalizeBrackets(result, "||")); } else { return(result); } }
/// <summary> /// Outputs a given expression tree to a string. /// </summary> /// <param name="node">The expression node.</param> /// <returns>The string representing the expression.</returns> public static new string ExpressionToString(Expression node) { node.CheckNotNull(nameof(node)); var expressionStringBuilder = new ObjectExpressionStringBuilder(node is LambdaExpression); try { expressionStringBuilder.Visit(node); return(expressionStringBuilder.CurrentLambda.Body.ToString()); } catch { return(node.ToString()); } }