CreateUnsupportedTypeException() private static method

private static CreateUnsupportedTypeException ( JsonWriter writer, object value ) : JsonWriterException
writer JsonWriter
value object
return JsonWriterException
Exemplo n.º 1
0
 public virtual void WriteValue(object value)
 {
     if (value == null)
     {
         this.WriteNull();
         return;
     }
     if (value is BigInteger)
     {
         throw JsonWriter.CreateUnsupportedTypeException(this, value);
     }
     JsonWriter.WriteValue(this, ConvertUtils.GetTypeCode(value), value);
 }
Exemplo n.º 2
0
        internal static void WriteValue(JsonWriter writer, PrimitiveTypeCode typeCode, object value)
        {
            switch (typeCode)
            {
            case PrimitiveTypeCode.Char:
                writer.WriteValue((char)value);
                return;

            case PrimitiveTypeCode.CharNullable:
                writer.WriteValue((value == null) ? null : new char?((char)value));
                return;

            case PrimitiveTypeCode.Boolean:
                writer.WriteValue((bool)value);
                return;

            case PrimitiveTypeCode.BooleanNullable:
                writer.WriteValue((value == null) ? null : new bool?((bool)value));
                return;

            case PrimitiveTypeCode.SByte:
                writer.WriteValue((sbyte)value);
                return;

            case PrimitiveTypeCode.SByteNullable:
                writer.WriteValue((value == null) ? null : new sbyte?((sbyte)value));
                return;

            case PrimitiveTypeCode.Int16:
                writer.WriteValue((short)value);
                return;

            case PrimitiveTypeCode.Int16Nullable:
                writer.WriteValue((value == null) ? null : new short?((short)value));
                return;

            case PrimitiveTypeCode.UInt16:
                writer.WriteValue((ushort)value);
                return;

            case PrimitiveTypeCode.UInt16Nullable:
                writer.WriteValue((value == null) ? null : new ushort?((ushort)value));
                return;

            case PrimitiveTypeCode.Int32:
                writer.WriteValue((int)value);
                return;

            case PrimitiveTypeCode.Int32Nullable:
                writer.WriteValue((value == null) ? null : new int?((int)value));
                return;

            case PrimitiveTypeCode.Byte:
                writer.WriteValue((byte)value);
                return;

            case PrimitiveTypeCode.ByteNullable:
                writer.WriteValue((value == null) ? null : new byte?((byte)value));
                return;

            case PrimitiveTypeCode.UInt32:
                writer.WriteValue((uint)value);
                return;

            case PrimitiveTypeCode.UInt32Nullable:
                writer.WriteValue((value == null) ? null : new uint?((uint)value));
                return;

            case PrimitiveTypeCode.Int64:
                writer.WriteValue((long)value);
                return;

            case PrimitiveTypeCode.Int64Nullable:
                writer.WriteValue((value == null) ? null : new long?((long)value));
                return;

            case PrimitiveTypeCode.UInt64:
                writer.WriteValue((ulong)value);
                return;

            case PrimitiveTypeCode.UInt64Nullable:
                writer.WriteValue((value == null) ? null : new ulong?((ulong)value));
                return;

            case PrimitiveTypeCode.Single:
                writer.WriteValue((float)value);
                return;

            case PrimitiveTypeCode.SingleNullable:
                writer.WriteValue((value == null) ? null : new float?((float)value));
                return;

            case PrimitiveTypeCode.Double:
                writer.WriteValue((double)value);
                return;

            case PrimitiveTypeCode.DoubleNullable:
                writer.WriteValue((value == null) ? null : new double?((double)value));
                return;

            case PrimitiveTypeCode.DateTime:
                writer.WriteValue((DateTime)value);
                return;

            case PrimitiveTypeCode.DateTimeNullable:
                writer.WriteValue((value == null) ? null : new DateTime?((DateTime)value));
                return;

            case PrimitiveTypeCode.DateTimeOffset:
                writer.WriteValue((DateTimeOffset)value);
                return;

            case PrimitiveTypeCode.DateTimeOffsetNullable:
                writer.WriteValue((value == null) ? null : new DateTimeOffset?((DateTimeOffset)value));
                return;

            case PrimitiveTypeCode.Decimal:
                writer.WriteValue((decimal)value);
                return;

            case PrimitiveTypeCode.DecimalNullable:
                writer.WriteValue((value == null) ? null : new decimal?((decimal)value));
                return;

            case PrimitiveTypeCode.Guid:
                writer.WriteValue((Guid)value);
                return;

            case PrimitiveTypeCode.GuidNullable:
                writer.WriteValue((value == null) ? null : new Guid?((Guid)value));
                return;

            case PrimitiveTypeCode.TimeSpan:
                writer.WriteValue((TimeSpan)value);
                return;

            case PrimitiveTypeCode.TimeSpanNullable:
                writer.WriteValue((value == null) ? null : new TimeSpan?((TimeSpan)value));
                return;

            case PrimitiveTypeCode.BigInteger:
                writer.WriteValue((BigInteger)value);
                return;

            case PrimitiveTypeCode.BigIntegerNullable:
                writer.WriteValue((value == null) ? null : new BigInteger?((BigInteger)value));
                return;

            case PrimitiveTypeCode.Uri:
                writer.WriteValue((Uri)value);
                return;

            case PrimitiveTypeCode.String:
                writer.WriteValue((string)value);
                return;

            case PrimitiveTypeCode.Bytes:
                writer.WriteValue((byte[])value);
                return;

            case PrimitiveTypeCode.DBNull:
                writer.WriteNull();
                return;

            default:
                if (value is IConvertible)
                {
                    IConvertible      convertible     = (IConvertible)value;
                    TypeInformation   typeInformation = ConvertUtils.GetTypeInformation(convertible);
                    PrimitiveTypeCode typeCode2       = (typeInformation.TypeCode == PrimitiveTypeCode.Object) ? PrimitiveTypeCode.String : typeInformation.TypeCode;
                    Type   conversionType             = (typeInformation.TypeCode == PrimitiveTypeCode.Object) ? typeof(string) : typeInformation.Type;
                    object value2 = convertible.ToType(conversionType, CultureInfo.InvariantCulture);
                    JsonWriter.WriteValue(writer, typeCode2, value2);
                    return;
                }
                throw JsonWriter.CreateUnsupportedTypeException(writer, value);
            }
        }