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));
        }
Example #2
0
        public JsonDictionaryContract(Type underlyingType) : base(underlyingType)
        {
            Type type;
            Type type2;

            base.enum15_0 = Enum15.Dictionary;
            if (Class194.smethod_14(underlyingType, typeof(IDictionary <,>), out this.type_3))
            {
                type  = this.type_3.GetGenericArguments()[0];
                type2 = this.type_3.GetGenericArguments()[1];
                if (Class194.smethod_12(base.UnderlyingType, typeof(IDictionary <,>)))
                {
                    base.CreatedType = typeof(Dictionary <,>).MakeGenericType(new Type[] { type, type2 });
                }
            }
            else
            {
                Class194.smethod_19(base.UnderlyingType, out type, out type2);
                if (base.UnderlyingType == typeof(IDictionary))
                {
                    base.CreatedType = typeof(Dictionary <object, object>);
                }
            }
            if ((type != null) && (type2 != null))
            {
                this.ConstructorInfo_0 = Class191.smethod_3(base.CreatedType, typeof(KeyValuePair <,>).MakeGenericType(new Type[] { type, type2 }));
            }
            this.Boolean_0           = !typeof(IDictionary).IsAssignableFrom(base.CreatedType);
            this.DictionaryKeyType   = type;
            this.DictionaryValueType = type2;
            if (this.DictionaryValueType != null)
            {
                this.bool_7 = Class194.smethod_10(this.DictionaryValueType);
            }
        }
Example #3
0
 internal static U smethod_2<T, U>(this T gparam_0) where T: JToken
 {
     if (gparam_0 == null)
     {
         return default(U);
     }
     if (((gparam_0 is U) && (typeof(U) != typeof(IComparable))) && (typeof(U) != typeof(IFormattable)))
     {
         return (U) gparam_0;
     }
     JValue value2 = gparam_0 as JValue;
     if (value2 == null)
     {
         throw new InvalidCastException("Cannot cast {0} to {1}.".smethod_1(CultureInfo.InvariantCulture, gparam_0.GetType(), typeof(T)));
     }
     if (value2.Value is U)
     {
         return (U) value2.Value;
     }
     Type underlyingType = typeof(U);
     if (Class194.smethod_10(underlyingType))
     {
         if (value2.Value == null)
         {
             return default(U);
         }
         underlyingType = Nullable.GetUnderlyingType(underlyingType);
     }
     return (U) Convert.ChangeType(value2.Value, underlyingType, CultureInfo.InvariantCulture);
 }
Example #4
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));
        }
Example #5
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));
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            bool flag;
            Type type = (flag = Class194.smethod_10(objectType)) ? Nullable.GetUnderlyingType(objectType) : objectType;

            if (reader.JsonToken_0 == JsonToken.Null)
            {
                if (!Class194.smethod_10(objectType))
                {
                    throw JsonSerializationException.smethod_1(reader, "Cannot convert null value to {0}.".smethod_0(CultureInfo.InvariantCulture, objectType));
                }
                return(null);
            }
            try
            {
                if (reader.JsonToken_0 == JsonToken.String)
                {
                    string str2;
                    string str = reader.Object_0.ToString();
                    if ((str == string.Empty) && flag)
                    {
                        return(null);
                    }
                    Class179 <string, string> class2 = this.method_0(type);
                    if (str.IndexOf(',') != -1)
                    {
                        string[] strArray = str.Split(new char[] { ',' });
                        for (int i = 0; i < strArray.Length; i++)
                        {
                            string str3 = strArray[i].Trim();
                            strArray[i] = smethod_0(class2, str3);
                        }
                        str2 = string.Join(", ", strArray);
                    }
                    else
                    {
                        str2 = smethod_0(class2, str);
                    }
                    return(Enum.Parse(type, str2, true));
                }
                if (reader.JsonToken_0 == JsonToken.Integer)
                {
                    return(Class181.smethod_10(reader.Object_0, CultureInfo.InvariantCulture, type));
                }
            }
            catch (Exception exception)
            {
                throw JsonSerializationException.smethod_2(reader, "Error converting value {0} to type '{1}'.".smethod_1(CultureInfo.InvariantCulture, Class193.smethod_7(reader.Object_0), objectType), exception);
            }
            throw JsonSerializationException.smethod_1(reader, "Unexpected token when parsing enum. Expected String or Integer, got {0}.".smethod_0(CultureInfo.InvariantCulture, reader.JsonToken_0));
        }
Example #7
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            bool flag;
            Type type = (flag = Class194.smethod_10(objectType)) ? Nullable.GetUnderlyingType(objectType) : objectType;

            if (reader.JsonToken_0 == JsonToken.Null)
            {
                if (!Class194.smethod_10(objectType))
                {
                    throw JsonSerializationException.smethod_1(reader, "Cannot convert null value to {0}.".smethod_0(CultureInfo.InvariantCulture, objectType));
                }
                return(null);
            }
            if (reader.JsonToken_0 == JsonToken.Date)
            {
                if (type == typeof(DateTimeOffset))
                {
                    return(new DateTimeOffset((DateTime)reader.Object_0));
                }
                return(reader.Object_0);
            }
            if (reader.JsonToken_0 != JsonToken.String)
            {
                throw JsonSerializationException.smethod_1(reader, "Unexpected token parsing date. Expected String, got {0}.".smethod_0(CultureInfo.InvariantCulture, reader.JsonToken_0));
            }
            string str = reader.Object_0.ToString();

            if (string.IsNullOrEmpty(str) && flag)
            {
                return(null);
            }
            if (type == typeof(DateTimeOffset))
            {
                if (!string.IsNullOrEmpty(this.string_1))
                {
                    return(DateTimeOffset.ParseExact(str, this.string_1, this.Culture, this.dateTimeStyles_0));
                }
                return(DateTimeOffset.Parse(str, this.Culture, this.dateTimeStyles_0));
            }
            if (!string.IsNullOrEmpty(this.string_1))
            {
                return(DateTime.ParseExact(str, this.string_1, this.Culture, this.dateTimeStyles_0));
            }
            return(DateTime.Parse(str, this.Culture, this.dateTimeStyles_0));
        }
Example #8
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            bool flag = Class194.smethod_10(objectType);

            if (reader.JsonToken_0 == JsonToken.Null)
            {
                if (!flag)
                {
                    throw JsonSerializationException.smethod_1(reader, "Cannot convert null value to KeyValuePair.");
                }
                return(null);
            }
            Type         type             = flag ? Nullable.GetUnderlyingType(objectType) : objectType;
            IList <Type> genericArguments = type.GetGenericArguments();
            Type         type2            = genericArguments[0];
            Type         type3            = genericArguments[1];
            object       obj2             = null;
            object       obj3             = null;

            reader.Read();
            while (reader.JsonToken_0 == JsonToken.PropertyName)
            {
                string a = reader.Object_0.ToString();
                if (string.Equals(a, "Key", StringComparison.OrdinalIgnoreCase))
                {
                    reader.Read();
                    obj2 = serializer.Deserialize(reader, type2);
                }
                else if (string.Equals(a, "Value", StringComparison.OrdinalIgnoreCase))
                {
                    reader.Read();
                    obj3 = serializer.Deserialize(reader, type3);
                }
                else
                {
                    reader.Skip();
                }
                reader.Read();
            }
            return(Activator.CreateInstance(type, new object[] { obj2, obj3 }));
        }
Example #9
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;
     }
 }
Example #10
0
        public override bool CanConvert(Type objectType)
        {
            Type type = Class194.smethod_10(objectType) ? Nullable.GetUnderlyingType(objectType) : objectType;

            return((type.smethod_12() && type.smethod_4()) && (type.GetGenericTypeDefinition() == typeof(KeyValuePair <,>)));
        }
Example #11
0
        public JsonArrayContract(Type underlyingType) : base(underlyingType)
        {
            bool flag;

            base.enum15_0 = Enum15.Array;
            if (base.CreatedType.IsArray)
            {
                this.CollectionItemType = Class194.smethod_18(base.UnderlyingType);
                base.bool_4             = true;
                this.type_3             = typeof(List <>).MakeGenericType(new Type[] { this.CollectionItemType });
                flag = true;
                this.IsMultidimensionalArray = base.UnderlyingType.IsArray && (base.UnderlyingType.GetArrayRank() > 1);
            }
            else if (typeof(IList).IsAssignableFrom(underlyingType))
            {
                if (Class194.smethod_14(underlyingType, typeof(ICollection <>), out this.type_3))
                {
                    this.CollectionItemType = this.type_3.GetGenericArguments()[0];
                }
                else
                {
                    this.CollectionItemType = Class194.smethod_18(underlyingType);
                }
                if (underlyingType == typeof(IList))
                {
                    base.CreatedType = typeof(List <object>);
                }
                if (this.CollectionItemType != null)
                {
                    this.ConstructorInfo_0 = Class191.smethod_3(underlyingType, this.CollectionItemType);
                }
                base.bool_4 = Class194.smethod_15(underlyingType, typeof(ReadOnlyCollection <>));
                flag        = true;
            }
            else if (Class194.smethod_14(underlyingType, typeof(ICollection <>), out this.type_3))
            {
                this.CollectionItemType = this.type_3.GetGenericArguments()[0];
                if (Class194.smethod_12(underlyingType, typeof(ICollection <>)) || Class194.smethod_12(underlyingType, typeof(IList <>)))
                {
                    base.CreatedType = typeof(List <>).MakeGenericType(new Type[] { this.CollectionItemType });
                }
                if (Class194.smethod_12(underlyingType, typeof(ISet <>)))
                {
                    base.CreatedType = typeof(HashSet <>).MakeGenericType(new Type[] { this.CollectionItemType });
                }
                this.ConstructorInfo_0 = Class191.smethod_3(underlyingType, this.CollectionItemType);
                flag           = true;
                this.Boolean_0 = true;
            }
            else
            {
                Type type;
                if (Class194.smethod_14(underlyingType, typeof(IEnumerable <>), out type))
                {
                    this.CollectionItemType = type.GetGenericArguments()[0];
                    if (Class194.smethod_12(base.UnderlyingType, typeof(IEnumerable <>)))
                    {
                        base.CreatedType = typeof(List <>).MakeGenericType(new Type[] { this.CollectionItemType });
                    }
                    this.ConstructorInfo_0 = Class191.smethod_3(underlyingType, this.CollectionItemType);
                    if (underlyingType.smethod_4() && (underlyingType.GetGenericTypeDefinition() == typeof(IEnumerable <>)))
                    {
                        this.type_3    = type;
                        base.bool_4    = false;
                        this.Boolean_0 = false;
                        flag           = true;
                    }
                    else
                    {
                        this.type_3    = typeof(List <>).MakeGenericType(new Type[] { this.CollectionItemType });
                        base.bool_4    = true;
                        this.Boolean_0 = true;
                        flag           = this.ConstructorInfo_0 != null;
                    }
                }
                else
                {
                    flag           = false;
                    this.Boolean_0 = true;
                }
            }
            this.Boolean_1 = flag;
            if (this.CollectionItemType != null)
            {
                this.bool_7 = Class194.smethod_10(this.CollectionItemType);
            }
        }
        public override bool CanConvert(Type objectType)
        {
            Type type = Class194.smethod_10(objectType) ? Nullable.GetUnderlyingType(objectType) : objectType;

            return(type.smethod_7());
        }
 internal static bool smethod_1(Type type_0)
 {
     return((typeof(IConvertible).IsAssignableFrom(type_0) || (Class194.smethod_10(type_0) && typeof(IConvertible).IsAssignableFrom(Nullable.GetUnderlyingType(type_0)))) && !typeof(JToken).IsAssignableFrom(type_0));
 }