Пример #1
0
        public void ExportTo <T>(ref T obj) where T : class
        {
            bool flag = obj == null;

            if (!flag)
            {
                if (!obj.IsObject())
                {
                    bool flag3 = this.ObjectType == JsonItemType.OBJ_ARRAY || this.ObjectType == JsonItemType.OBJ_OBJECT;
                    if (flag3)
                    {
                        object tempobj = null;
                        if (this.ObjectType == JsonItemType.OBJ_ARRAY)
                        {
                            bool flag5 = obj.IsArray();
                            if (flag5)
                            {
                                bool flag6 = obj is Array;
                                if (flag6)
                                {
                                    Array array = obj as Array;
                                    bool  flag7 = array.Length < this.SubItems.Count;
                                    if (flag7)
                                    {
                                        JsonItem.Resize(ref array, this.SubItems.Count);
                                    }
                                    obj = (array as T);
                                }
                            }
                            IDictionary idict;
                            bool        flag8 = (idict = (obj as IDictionary)) != null;
                            if (flag8)
                            {
                                object[] nobj = new object[this.SubItems.Count];
                                idict.Add(this.Name, nobj);
                                tempobj = nobj;
                            }
                            else
                            {
                                IDictionary <string, object> ndict;
                                if ((ndict = (obj as IDictionary <string, object>)) != null)
                                {
                                    Dictionary <string, object> nobj2 = new Dictionary <string, object>();
                                    ndict.Add(this.Name, nobj2);
                                    tempobj = nobj2;
                                }
                            }
                        }
                        else
                        {
                            if (obj is Array)
                            {
                                IList arr = obj as IList;
                                Dictionary <string, object> nobj3 = new Dictionary <string, object>();
                                tempobj         = nobj3;
                                arr[this.Index] = ReflectUtil.MatchType(nobj3, obj.GetType().GetElementType());
                            }
                            bool flag11 = this.Parent != null;
                            if (flag11)
                            {
                                IDictionary idict2;
                                if ((idict2 = (obj as IDictionary)) != null)
                                {
                                    Type otypee  = obj.GetType();
                                    Type gentype = otypee.GetGenericArguments().ElementAt(1);
                                    bool flag13  = gentype != typeof(object);
                                    if (flag13)
                                    {
                                        return;
                                    }
                                    Type   listType            = typeof(Dictionary <,>);
                                    Type   constructedListType = listType.MakeGenericType(otypee.GetGenericArguments());
                                    object nobj4 = Activator.CreateInstance(constructedListType);
                                    idict2.Add(this.Name, nobj4);
                                    tempobj = nobj4;
                                }
                                else
                                {
                                    IDictionary <string, object> ndict2;
                                    bool flag14 = (ndict2 = (obj as IDictionary <string, object>)) != null;
                                    if (flag14)
                                    {
                                        Dictionary <string, object> nobj5 = new Dictionary <string, object>();
                                        ndict2.Add(this.Name, nobj5);
                                        tempobj = nobj5;
                                    }
                                }
                            }
                        }
                        for (int i = 0; i < this.SubItems.Count; i++)
                        {
                            JsonItem item   = this.SubItems[i];
                            bool     flag15 = tempobj != null;
                            if (flag15)
                            {
                                item.ExportTo <object>(ref tempobj);
                            }
                            else
                            {
                                item.ExportTo <T>(ref obj);
                            }
                        }
                    }
                    else
                    {
                        bool flag16 = this.ObjectType == JsonItemType.OBJ_ARRAYITEM;
                        if (flag16)
                        {
                            IList list;
                            bool  flag17 = (list = (obj as IList)) != null;
                            if (flag17)
                            {
                                Type ntype         = list.GetType();
                                bool isGenericType = ntype.IsGenericType;
                                Type ltype;
                                if (isGenericType)
                                {
                                    ltype = ntype.GetGenericArguments().FirstOrDefault <Type>();
                                }
                                else
                                {
                                    ltype = list.GetType().GetElementType();
                                }
                                bool isFixedSize = list.IsFixedSize;
                                if (isFixedSize)
                                {
                                    list[this.Index] = ReflectUtil.MatchType(this.Value, ltype);
                                }
                                else
                                {
                                    list.Add(ReflectUtil.MatchType(this.Value, ltype));
                                }
                            }
                        }
                        else
                        {
                            if (this.ObjectType == JsonItemType.OBJ_VARIANT)
                            {
                                T           t     = obj;
                                Type        otype = t?.GetType();
                                IDictionary idict3;
                                bool        flag19 = (idict3 = (obj as IDictionary)) != null;
                                if (flag19)
                                {
                                    Type gentype2 = otype.GetGenericArguments().ElementAt(1);
                                    idict3.Add(this.Name, ReflectUtil.MatchType(this.Value, gentype2));
                                }
                                else
                                {
                                    IDictionary <string, object> sdict;
                                    if ((sdict = (obj as IDictionary <string, object>)) != null)
                                    {
                                        sdict.Add(this.Name, this.Value);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    bool flag21 = this.ObjectType != JsonItemType.OBJ_OBJECT;
                    if (!flag21)
                    {
                        Type         otype2  = obj.GetType();
                        MemberInfo[] members = otype2.GetMembers(BindingFlags.Instance | BindingFlags.Public);
                        foreach (MemberInfo member in members)
                        {
                            bool flag22 = member.MemberType != MemberTypes.Field && member.MemberType != MemberTypes.Property;
                            if (!flag22)
                            {
                                string        name = member.Name;
                                JsonAttribute jattribut;
                                if ((jattribut = (member.GetCustomAttribute(typeof(JsonAttribute)) as JsonAttribute)) != null)
                                {
                                    bool notMapped = jattribut.NotMapped;
                                    if (notMapped)
                                    {
                                        goto IL_7E6;
                                    }
                                    bool flag24 = !string.IsNullOrEmpty(jattribut.TagName);
                                    if (flag24)
                                    {
                                        name = jattribut.TagName;
                                    }
                                }
                                JsonItem item2  = this.Find(name);
                                bool     flag25 = item2 == null;
                                if (!flag25)
                                {
                                    FieldPropertyInfo fprop = new FieldPropertyInfo(member);
                                    bool flag26             = !fprop.CanWrite || !fprop.CanRead || fprop.HasIndexParameters();
                                    if (!flag26)
                                    {
                                        if (item2.ObjectType == JsonItemType.OBJ_OBJECT)
                                        {
                                            bool flag28 = !fprop.ObjectType.IsObject() && !fprop.ObjectType.IsDictionary();
                                            if (!flag28)
                                            {
                                                object curvalue = fprop.GetValue(obj);
                                                if (curvalue == null)
                                                {
                                                    if (fprop.ObjectType.IsDictionary())
                                                    {
                                                        Type listType2            = typeof(Dictionary <,>);
                                                        Type constructedListType2 = listType2.MakeGenericType(fprop.ObjectType.GetGenericArguments());
                                                        curvalue = Activator.CreateInstance(constructedListType2);
                                                        for (int j = 0; j < item2.SubItems.Count; j++)
                                                        {
                                                            item2.SubItems[j].ExportTo <object>(ref curvalue);
                                                        }
                                                        fprop.SetValue(obj, curvalue);
                                                        break;
                                                    }
                                                    curvalue = Activator.CreateInstance(fprop.ObjectType);
                                                }
                                                item2.ExportTo <object>(ref curvalue);
                                                fprop.SetValue(obj, curvalue);
                                            }
                                        }
                                        else
                                        {
                                            if (item2.ObjectType == JsonItemType.OBJ_ARRAY)
                                            {
                                                bool flag32 = !fprop.ObjectType.IsArray();
                                                if (!flag32)
                                                {
                                                    object curvalue2 = fprop.GetValue(obj);
                                                    if (curvalue2 == null)
                                                    {
                                                        Type listType3      = typeof(List <>);
                                                        bool isGenericType2 = fprop.ObjectType.IsGenericType;
                                                        if (isGenericType2)
                                                        {
                                                            Type constructedListType3 = listType3.MakeGenericType(fprop.ObjectType.GetGenericArguments());
                                                            curvalue2 = Activator.CreateInstance(constructedListType3);
                                                        }
                                                        else
                                                        {
                                                            Type elemtype = fprop.ObjectType.GetElementType();
                                                            if (elemtype != null)
                                                            {
                                                                curvalue2 = Array.CreateInstance(elemtype, item2.SubItems.Count);
                                                            }
                                                        }
                                                    }
                                                    item2.ExportTo <object>(ref curvalue2);
                                                    fprop.SetValue(obj, curvalue2);
                                                }
                                            }
                                            else
                                            {
                                                if (!fprop.ObjectType.IsObject() && !member.MemberType.IsArray())
                                                {
                                                    fprop.SetValue(obj, ReflectUtil.MatchType(item2.Value, fprop.ObjectType));
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            IL_7E6 :;
                        }
                    }
                }
            }
        }