Exemple #1
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);
            }
        }
        private ExtensionDataSetter method_3(Type type_0)
        {
            ExtensionDataSetter setter = null;

            foreach (Type type in this.method_10(type_0))
            {
                IList <MemberInfo> list = new List <MemberInfo>();
                list.smethod_1 <MemberInfo>(type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly));
                list.smethod_1 <MemberInfo>(type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly));
                using (IEnumerator <MemberInfo> enumerator2 = list.GetEnumerator())
                {
                    MemberInfo current;
                    while (enumerator2.MoveNext())
                    {
                        current = enumerator2.Current;
                        MemberTypes types = current.smethod_1();
                        if (((types == MemberTypes.Property) || (types == MemberTypes.Field)) && current.IsDefined(typeof(JsonExtensionDataAttribute), false))
                        {
                            Type type3;
                            Type type2 = Class194.smethod_20(current);
                            if (!Class194.smethod_14(type2, typeof(IDictionary <,>), out type3))
                            {
                                goto Label_01AF;
                            }
                            Type type4 = type3.GetGenericArguments()[0];
                            Type type5 = type3.GetGenericArguments()[1];
                            if (Class194.smethod_12(type2, typeof(IDictionary <,>)))
                            {
                                type2 = typeof(Dictionary <,>).MakeGenericType(new Type[] { type4, type5 });
                            }
                            if (!type4.IsAssignableFrom(typeof(string)) || !type5.IsAssignableFrom(typeof(JToken)))
                            {
                                goto Label_01AF;
                            }
                            Class126   class2 = new Class126();
                            MethodInfo method = type2.GetMethod("Add", new Type[] { type4, type5 });
                            class2.func_0      = Class139.Class166_0.method_0 <object>(current);
                            class2.action_0    = Class139.Class166_0.method_1 <object>(current);
                            class2.func_1      = Class139.Class166_0.ns20.Class166.‏‍‍‍‮‪‌‍‏‭‎‭​‬‪‬‪‮‬​‫‫‎‮‏‮ <object>(type2);
                            class2.delegate3_0 = Class139.Class166_0.ns20.Class166.‫‌‪‭‭‪‌‎‮‬​‌‌‬‎‮‌‏‌‎‪‌‏‬‫‭‮ <object>(method);
                            setter             = new ExtensionDataSetter(class2.method_0);
                        }
                    }
                    continue;
Label_01AF:
                    throw new JsonException("Invalid extension data attribute on '{0}'. Member '{1}' type must implement IDictionary<string, JToken>.".smethod_1(CultureInfo.InvariantCulture, smethod_4(current.DeclaringType), current.Name));
                }
            }
            return(setter);
        }
Exemple #3
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);
            }
        }