Пример #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            Type type = Class194.smethod_10(objectType) ? Nullable.GetUnderlyingType(objectType) : objectType;

            if (reader.JsonToken_0 == JsonToken.Null)
            {
                if (!Class194.smethod_9(objectType))
                {
                    throw JsonSerializationException.smethod_1(reader, "Cannot convert null value to {0}.".smethod_0(CultureInfo.InvariantCulture, objectType));
                }
                return(null);
            }
            if ((reader.JsonToken_0 != JsonToken.StartConstructor) || !string.Equals(reader.Object_0.ToString(), "Date", StringComparison.Ordinal))
            {
                throw JsonSerializationException.smethod_1(reader, "Unexpected token or value when parsing date. Token: {0}, Value: {1}".smethod_1(CultureInfo.InvariantCulture, reader.JsonToken_0, reader.Object_0));
            }
            reader.Read();
            if (reader.JsonToken_0 != JsonToken.Integer)
            {
                throw JsonSerializationException.smethod_1(reader, "Unexpected token parsing date. Expected Integer, got {0}.".smethod_0(CultureInfo.InvariantCulture, reader.JsonToken_0));
            }
            long     num      = (long)reader.Object_0;
            DateTime dateTime = Class184.smethod_11(num);

            reader.Read();
            if (reader.JsonToken_0 != JsonToken.EndConstructor)
            {
                throw JsonSerializationException.smethod_1(reader, "Unexpected token parsing date. Expected EndConstructor, got {0}.".smethod_0(CultureInfo.InvariantCulture, reader.JsonToken_0));
            }
            if (!(type == typeof(DateTimeOffset)))
            {
                return(dateTime);
            }
            return(new DateTimeOffset(dateTime));
        }
Пример #2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            byte[] buffer;
            Type   type = Class194.smethod_10(objectType) ? Nullable.GetUnderlyingType(objectType) : objectType;

            if (reader.JsonToken_0 == JsonToken.Null)
            {
                if (!Class194.smethod_9(objectType))
                {
                    throw JsonSerializationException.smethod_1(reader, "Cannot convert null value to {0}.".smethod_0(CultureInfo.InvariantCulture, objectType));
                }
                return(null);
            }
            if (reader.JsonToken_0 == JsonToken.StartArray)
            {
                buffer = this.method_1(reader);
            }
            else
            {
                if (reader.JsonToken_0 != JsonToken.String)
                {
                    throw JsonSerializationException.smethod_1(reader, "Unexpected token parsing binary. Expected String or StartArray, got {0}.".smethod_0(CultureInfo.InvariantCulture, reader.JsonToken_0));
                }
                buffer = Convert.FromBase64String(reader.Object_0.ToString());
            }
            if (type.smethod_14("System.Data.Linq.Binary"))
            {
                return(Activator.CreateInstance(type, new object[] { buffer }));
            }
            if (type != typeof(SqlBinary))
            {
                throw JsonSerializationException.smethod_1(reader, "Unexpected object type when writing binary: {0}".smethod_0(CultureInfo.InvariantCulture, objectType));
            }
            return(new SqlBinary(buffer));
        }
Пример #3
0
        private JsonSchemaType method_10(Type type_0, Required required_0)
        {
            JsonSchemaType none = JsonSchemaType.None;

            if ((required_0 != Required.Always) && Class194.smethod_9(type_0))
            {
                none = JsonSchemaType.Null;
                if (Class194.smethod_10(type_0))
                {
                    type_0 = Nullable.GetUnderlyingType(type_0);
                }
            }
            Enum17 enum2 = Class181.smethod_0(type_0);

            switch (enum2)
            {
            case Enum17.Empty:
            case Enum17.Object:
                return(none | JsonSchemaType.String);

            case Enum17.Char:
                return(none | JsonSchemaType.String);

            case Enum17.Boolean:
                return(none | JsonSchemaType.Boolean);

            case Enum17.SByte:
            case Enum17.Int16:
            case Enum17.UInt16:
            case Enum17.Int32:
            case Enum17.Byte:
            case Enum17.UInt32:
            case Enum17.Int64:
            case Enum17.UInt64:
            case Enum17.BigInteger:
                return(none | JsonSchemaType.Integer);

            case Enum17.Single:
            case Enum17.Double:
            case Enum17.Decimal:
                return(none | JsonSchemaType.Float);

            case Enum17.DateTime:
            case Enum17.DateTimeOffset:
                return(none | JsonSchemaType.String);

            case Enum17.Guid:
            case Enum17.TimeSpan:
            case Enum17.Uri:
            case Enum17.String:
            case Enum17.Bytes:
                return(none | JsonSchemaType.String);

            case Enum17.DBNull:
                return(none | JsonSchemaType.Null);
            }
            throw new JsonException("Unexpected type code '{0}' for type '{1}'.".smethod_1(CultureInfo.InvariantCulture, enum2, type_0));
        }
Пример #4
0
 internal JsonContract(Type underlyingType)
 {
     Class203.smethod_2(underlyingType, "underlyingType");
     this.UnderlyingType = underlyingType;
     this.bool_2         = underlyingType.smethod_9();
     this.bool_5         = !underlyingType.smethod_3() && !underlyingType.smethod_10();
     this.bool_0         = Class194.smethod_9(underlyingType);
     this.type_0         = (!this.bool_0 || !Class194.smethod_10(underlyingType)) ? underlyingType : Nullable.GetUnderlyingType(underlyingType);
     this.CreatedType    = this.type_0;
     this.bool_1         = Class181.smethod_3(this.type_0);
     this.bool_3         = this.type_0.smethod_7();
     if (this.type_0 == typeof(byte[]))
     {
         this.enum14_0 = Enum14.ReadAsBytes;
     }
     else if (this.type_0 == typeof(int))
     {
         this.enum14_0 = Enum14.ReadAsInt32;
     }
     else if (this.type_0 == typeof(decimal))
     {
         this.enum14_0 = Enum14.ReadAsDecimal;
     }
     else if (this.type_0 == typeof(string))
     {
         this.enum14_0 = Enum14.ReadAsString;
     }
     else if (this.type_0 == typeof(DateTime))
     {
         this.enum14_0 = Enum14.ReadAsDateTime;
     }
     else if (this.type_0 == typeof(DateTimeOffset))
     {
         this.enum14_0 = Enum14.ReadAsDateTimeOffset;
     }
     else
     {
         this.enum14_0 = Enum14.Read;
     }
 }
Пример #5
0
        private JsonSchema method_5(Type type_0, Required required_0, bool bool_0)
        {
            JsonConverter converter;
            Class134      class4 = new Class134 {
                type_0 = type_0
            };

            Class203.smethod_2(class4.type_0, "type");
            string str  = this.method_4(class4.type_0, false);
            string str2 = this.method_4(class4.type_0, true);

            if (!string.IsNullOrEmpty(str))
            {
                JsonSchema schema = this.jsonSchemaResolver_0.GetSchema(str);
                if (schema != null)
                {
                    if ((required_0 != Required.Always) && !smethod_0(schema.Type, JsonSchemaType.Null))
                    {
                        schema.Type = ((JsonSchemaType)schema.Type) | JsonSchemaType.Null;
                    }
                    if (bool_0 && (schema.Required != true))
                    {
                        schema.Required = true;
                    }
                    return(schema);
                }
            }
            if (this.ilist_0.Any <Class133>(new Func <Class133, bool>(class4.method_0)))
            {
                throw new JsonException("Unresolved circular reference for type '{0}'. Explicitly define an Id for the type using a JsonObject/JsonArray attribute or automatically generate a type Id using the UndefinedSchemaIdHandling property.".smethod_0(CultureInfo.InvariantCulture, class4.type_0));
            }
            JsonContract contract = this.ContractResolver.ResolveContract(class4.type_0);

            if (((converter = contract.Converter) != null) || ((converter = contract.JsonConverter_0) != null))
            {
                JsonSchema schema2 = converter.GetSchema();
                if (schema2 != null)
                {
                    return(schema2);
                }
            }
            this.method_0(new Class133(class4.type_0, new JsonSchema()));
            if (str2 != null)
            {
                this.JsonSchema_0.Id = str2;
            }
            if (bool_0)
            {
                this.JsonSchema_0.Required = true;
            }
            this.JsonSchema_0.Title       = this.method_2(class4.type_0);
            this.JsonSchema_0.Description = this.method_3(class4.type_0);
            if (converter != null)
            {
                this.JsonSchema_0.Type = 0x7f;
            }
            else
            {
                switch (contract.enum15_0)
                {
                case Enum15.Object:
                    this.JsonSchema_0.Type = new JsonSchemaType?(this.method_6(JsonSchemaType.Object, required_0));
                    this.JsonSchema_0.Id   = this.method_4(class4.type_0, false);
                    this.method_8(class4.type_0, (JsonObjectContract)contract);
                    goto Label_04CD;

                case Enum15.Array:
                    {
                        this.JsonSchema_0.Type = new JsonSchemaType?(this.method_6(JsonSchemaType.Array, required_0));
                        this.JsonSchema_0.Id   = this.method_4(class4.type_0, false);
                        JsonArrayAttribute attribute = Class139.smethod_0(class4.type_0) as JsonArrayAttribute;
                        bool flag = (attribute == null) || attribute.AllowNullItems;
                        Type type = Class194.smethod_18(class4.type_0);
                        if (type != null)
                        {
                            this.JsonSchema_0.Items = new List <JsonSchema>();
                            this.JsonSchema_0.Items.Add(this.method_5(type, !flag ? Required.Always : Required.Default, false));
                        }
                        goto Label_04CD;
                    }

                case Enum15.Primitive:
                    this.JsonSchema_0.Type = new JsonSchemaType?(this.method_10(class4.type_0, required_0));
                    if (((((JsonSchemaType)this.JsonSchema_0.Type) == JsonSchemaType.Integer) && class4.type_0.smethod_7()) && !class4.type_0.IsDefined(typeof(FlagsAttribute), true))
                    {
                        this.JsonSchema_0.Enum = new List <JToken>();
                        foreach (Class187 <long> class3 in Class186.smethod_2 <long>(class4.type_0))
                        {
                            JToken item = JToken.FromObject(class3.Prop_0);
                            this.JsonSchema_0.Enum.Add(item);
                        }
                    }
                    goto Label_04CD;

                case Enum15.String:
                    {
                        JsonSchemaType type2 = !Class194.smethod_9(contract.UnderlyingType) ? JsonSchemaType.String : this.method_6(JsonSchemaType.String, required_0);
                        this.JsonSchema_0.Type = new JsonSchemaType?(type2);
                        goto Label_04CD;
                    }

                case Enum15.Dictionary:
                    Type type3;
                    Type type4;
                    this.JsonSchema_0.Type = new JsonSchemaType?(this.method_6(JsonSchemaType.Object, required_0));
                    Class194.smethod_19(class4.type_0, out type3, out type4);
                    if ((type3 != null) && (this.ContractResolver.ResolveContract(type3).enum15_0 == Enum15.Primitive))
                    {
                        this.JsonSchema_0.AdditionalProperties = this.method_5(type4, Required.Default, false);
                    }
                    goto Label_04CD;

                case Enum15.Dynamic:
                case Enum15.Linq:
                    this.JsonSchema_0.Type = 0x7f;
                    goto Label_04CD;

                case Enum15.Serializable:
                    this.JsonSchema_0.Type = new JsonSchemaType?(this.method_6(JsonSchemaType.Object, required_0));
                    this.JsonSchema_0.Id   = this.method_4(class4.type_0, false);
                    this.method_9(class4.type_0, (JsonISerializableContract)contract);
                    goto Label_04CD;
                }
                throw new JsonException("Unexpected contract type: {0}".smethod_0(CultureInfo.InvariantCulture, contract));
            }
Label_04CD:
            return(this.method_1().JsonSchema_0);
        }