Exemple #1
0
        private void AppendArrayBound(StringBuilder sb, long bound)
        {
            CommonPrimitiveFormatterOptions options = new CommonPrimitiveFormatterOptions();
            string str = int.MinValue > bound || bound > int.MaxValue ? this.PrimitiveFormatter.FormatPrimitive(bound, options) : this.PrimitiveFormatter.FormatPrimitive((int)bound, options);

            sb.Append(str);
        }
        public string FormatPrimitive(object obj, CommonPrimitiveFormatterOptions options)
        {
            if (obj == ObjectFormatterHelpers.VoidValue)
            {
                return(string.Empty);
            }
            if (obj == null)
            {
                return(this.NullLiteral);
            }
            Type type = obj.GetType();

            if (IntrospectionExtensions.GetTypeInfo(type).IsEnum)
            {
                return(obj.ToString());
            }
            switch (ObjectFormatterHelpers.GetPrimitiveSpecialType(type))
            {
            case SpecialType.None:
            case SpecialType.System_Object:
            case SpecialType.System_Void:
                return(null);

            case SpecialType.System_Boolean:
                return(this.FormatLiteral((bool)obj));

            case SpecialType.System_Char:
                return(this.FormatLiteral((char)obj, options.QuoteStringsAndCharacters, options.EscapeNonPrintableCharacters, options.IncludeCharacterCodePoints));

            case SpecialType.System_SByte:
                return(this.FormatLiteral((sbyte)obj, options.CultureInfo));

            case SpecialType.System_Byte:
                return(this.FormatLiteral((byte)obj, options.CultureInfo));

            case SpecialType.System_Int16:
                return(this.FormatLiteral((short)obj, options.CultureInfo));

            case SpecialType.System_UInt16:
                return(this.FormatLiteral((ushort)obj, options.CultureInfo));

            case SpecialType.System_Int32:
                return(this.FormatLiteral((int)obj, options.CultureInfo));

            case SpecialType.System_UInt32:
                return(this.FormatLiteral((uint)obj, options.CultureInfo));

            case SpecialType.System_Int64:
                return(this.FormatLiteral((long)obj, options.CultureInfo));

            case SpecialType.System_UInt64:
                return(this.FormatLiteral((ulong)obj, options.CultureInfo));

            case SpecialType.System_Decimal:
                return(this.FormatLiteral((Decimal)obj, options.CultureInfo));

            case SpecialType.System_Single:
                return(this.FormatLiteral((float)obj, options.CultureInfo));

            case SpecialType.System_Double:
                return(this.FormatLiteral((double)obj, options.CultureInfo));

            case SpecialType.System_String:
                return(this.FormatLiteral((string)obj, options.QuoteStringsAndCharacters, options.EscapeNonPrintableCharacters));

            case SpecialType.System_DateTime:
                return(this.FormatLiteral((DateTime)obj, options.CultureInfo));

            default:
                throw new NotSupportedException(ObjectFormatterHelpers.GetPrimitiveSpecialType(type).ToString());
            }
        }