/// <summary>
 /// Formats <see cref="SyntaxTreeNode"/> into string representation.
 /// </summary>
 /// <param name="syntaxTree">An valid syntax tree.</param>
 /// <param name="checkedScope">True to assume all arithmetic and conversion operation is checked for overflows.</param>
 /// <returns>C# formatted expression.</returns>
 public static string Format(this SyntaxTreeNode syntaxTree, bool checkedScope = DEFAULT_CHECKED_SCOPE)
 {
     return(CSharpSyntaxTreeFormatter.Format(syntaxTree, checkedScope));
 }
        private static void RenderConstant(ConstantExpression expression, StringBuilder builder)
        {
            if (expression == null)
            {
                throw new ArgumentException("expression");
            }
            if (builder == null)
            {
                throw new ArgumentException("builder");
            }

            if (expression.Value == null)
            {
                if (expression.Type == typeof(object))
                {
                    builder.Append("null");
                    return;
                }
                else
                {
                    builder.Append("default(");
                    RenderType(expression.Type, builder);
                    builder.Append(")");
                    return;
                }
            }

            var strValue = Convert.ToString(expression.Value, Constants.DefaultFormatProvider) ?? string.Empty;

            if (expression.Type == typeof(string))
            {
                CSharpSyntaxTreeFormatter.RenderTextLiteral(strValue, builder, isChar: false);
            }
            else if (expression.Type == typeof(char))
            {
                CSharpSyntaxTreeFormatter.RenderTextLiteral(strValue, builder, isChar: true);
            }
            else if (expression.Type == typeof(Type))
            {
                builder.Append("typeof(");
                RenderType((Type)expression.Value, builder);
                builder.Append(")");
            }
            else if (expression.Type == typeof(ushort) || expression.Type == typeof(uint))
            {
                builder.Append(strValue).Append("u");
            }
            else if (expression.Type == typeof(ulong))
            {
                builder.Append(strValue).Append("ul");
            }
            else if (expression.Type == typeof(long))
            {
                builder.Append(strValue).Append("l");
            }
            else if (expression.Type == typeof(float) || expression.Type == typeof(double))
            {
                var is32Bit     = expression.Type == typeof(float);
                var doubleValue = Convert.ToDouble(expression.Value, Constants.DefaultFormatProvider);

                if (double.IsPositiveInfinity(doubleValue))
                {
                    builder.Append(is32Bit ? "System.Single.PositiveInfinity" : "System.Double.PositiveInfinity");
                }
                if (double.IsNegativeInfinity(doubleValue))
                {
                    builder.Append(is32Bit ? "System.Single.NegativeInfinity" : "System.Double.NegativeInfinity");
                }
                if (double.IsNaN(doubleValue))
                {
                    builder.Append(is32Bit ? "System.Single.NaN" : "System.Double.NaN");
                }
                else
                {
                    builder.Append(doubleValue.ToString("R", Constants.DefaultFormatProvider));
                }
                builder.Append(is32Bit ? "f" : "d");
            }
            else if (expression.Type == typeof(decimal))
            {
                builder.Append(strValue).Append("m");
            }
            else if (expression.Type == typeof(bool))
            {
                builder.Append(strValue.ToLowerInvariant());
            }
            else if (expression.Type == typeof(byte) || expression.Type == typeof(sbyte) || expression.Type == typeof(short) || expression.Type == typeof(int))
            {
                builder.Append(strValue);
            }
            else
            {
                throw new InvalidOperationException(string.Format(Properties.Resources.EXCEPTION_BIND_INVALIDCONSTANTEXPRESSION, expression.Type));
            }
        }