Exemple #1
0
        public TypedObject GetBaseTypedObject()
        {
            TypedObject obj2 = new TypedObject(this.TypeName);
            Type        type = base.GetType();

            foreach (PropertyInfo info in type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                InternalNameAttribute attribute = info.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault <object>() as InternalNameAttribute;
                if (attribute != null)
                {
                    object item         = null;
                    Type   propertyType = info.PropertyType;
                    string name         = propertyType.Name;
                    if (propertyType == typeof(int[]))
                    {
                        int[] source = info.GetValue(this) as int[];
                        if (source != null)
                        {
                            item = source.Cast <object>().ToArray <object>();
                        }
                    }
                    else if (propertyType == typeof(double[]))
                    {
                        double[] numArray2 = info.GetValue(this) as double[];
                        if (numArray2 != null)
                        {
                            item = numArray2.Cast <object>().ToArray <object>();
                        }
                    }
                    else if (propertyType == typeof(string[]))
                    {
                        string[] strArray = info.GetValue(this) as string[];
                        if (strArray != null)
                        {
                            item = strArray.Cast <object>().ToArray <object>();
                        }
                    }
                    else if (propertyType.IsGenericType && (propertyType.GetGenericTypeDefinition() == typeof(List <>)))
                    {
                        IList list = info.GetValue(this) as IList;
                        if (list != null)
                        {
                            object[] array = new object[list.Count];
                            list.CopyTo(array, 0);
                            List <object> list2 = new List <object>();
                            foreach (object obj4 in array)
                            {
                                Type c = obj4.GetType();
                                if (typeof(RiotGamesObject).IsAssignableFrom(c))
                                {
                                    item = (obj4 as RiotGamesObject).GetBaseTypedObject();
                                }
                                else
                                {
                                    item = obj4;
                                }
                                list2.Add(item);
                            }
                            item = TypedObject.MakeArrayCollection(list2.ToArray());
                        }
                    }
                    else if (typeof(RiotGamesObject).IsAssignableFrom(propertyType))
                    {
                        RiotGamesObject obj5 = info.GetValue(this) as RiotGamesObject;
                        if (obj5 != null)
                        {
                            item = obj5.GetBaseTypedObject();
                        }
                    }
                    else
                    {
                        item = info.GetValue(this);
                    }
                    obj2.Add(attribute.Name, item);
                }
            }
            Type baseType = type.BaseType;

            if (baseType != null)
            {
                foreach (PropertyInfo info2 in baseType.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                {
                    InternalNameAttribute attribute2 = info2.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault <object>() as InternalNameAttribute;
                    if ((attribute2 != null) && !obj2.ContainsKey(attribute2.Name))
                    {
                        obj2.Add(attribute2.Name, info2.GetValue(this));
                    }
                }
            }
            return(obj2);
        }
        public TypedObject GetBaseTypedObject()
        {
            TypedObject typedObject = new TypedObject(TypeName);
            Type        objectType  = this.GetType();

            foreach (var prop in objectType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                var intern = prop.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault() as InternalNameAttribute;
                if (intern == null)
                {
                    continue;
                }

                object value = null;

                var type = prop.PropertyType;

                string typeName = type.Name;
                if (type == typeof(int[]))
                {
                    var test = prop.GetValue(this) as int[];
                    if (test != null)
                    {
                        value = test.Cast <object>().ToArray();
                    }
                }
                else if (type == typeof(double[]))
                {
                    var test = prop.GetValue(this) as double[];
                    if (test != null)
                    {
                        value = test.Cast <object>().ToArray();
                    }
                }
                else if (type == typeof(string[]))
                {
                    var test = prop.GetValue(this) as string[];
                    if (test != null)
                    {
                        value = test.Cast <object>().ToArray();
                    }
                }
                //List = Array Collection. Object array = object array
                else if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List <>))
                {
                    IList listValues = prop.GetValue(this) as IList;
                    if (listValues != null)
                    {
                        object[] finalArray = new object[listValues.Count];
                        listValues.CopyTo(finalArray, 0);
                        List <object> finalObjList = new List <object>();
                        foreach (object ob in finalArray)
                        {
                            Type obType = ob.GetType();

                            if (typeof(RiotGamesObject).IsAssignableFrom(obType))
                            {
                                RiotGamesObject rgo = ob as RiotGamesObject;

                                value = rgo.GetBaseTypedObject();
                            }

                            else
                            {
                                value = ob;
                            }

                            finalObjList.Add(value);
                        }
                        value = TypedObject.MakeArrayCollection(finalObjList.ToArray());
                    }
                }
                else if (typeof(RiotGamesObject).IsAssignableFrom(type))
                {
                    RiotGamesObject rgo = prop.GetValue(this) as RiotGamesObject;

                    if (rgo != null)
                    {
                        value = rgo.GetBaseTypedObject();
                    }
                }
                else
                {
                    value = prop.GetValue(this);
                }

                typedObject.Add(intern.Name, value);
            }

            Type objectBaseType = objectType.BaseType;

            if (objectBaseType != null)
            {
                foreach (var prop in objectBaseType.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                {
                    var intern = prop.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault() as InternalNameAttribute;
                    if (intern == null || typedObject.ContainsKey(intern.Name))
                    {
                        continue;
                    }

                    typedObject.Add(intern.Name, prop.GetValue(this));
                }
            }

            return(typedObject);
        }
        public TypedObject GetBaseTypedObject()
        {
            TypedObject typedObject = new TypedObject(this.TypeName);
            Type        type        = base.GetType();

            PropertyInfo[] properties = type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            for (int i = 0; i < properties.Length; i++)
            {
                PropertyInfo          propertyInfo          = properties[i];
                InternalNameAttribute internalNameAttribute = propertyInfo.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault <object>() as InternalNameAttribute;
                if (internalNameAttribute != null)
                {
                    object obj          = null;
                    Type   propertyType = propertyInfo.PropertyType;
                    string arg_5F_0     = propertyType.Name;
                    if (propertyType == typeof(int[]))
                    {
                        int[] array = propertyInfo.GetValue(this) as int[];
                        if (array != null)
                        {
                            obj = array.Cast <object>().ToArray <object>();
                        }
                    }
                    else if (propertyType == typeof(double[]))
                    {
                        double[] array2 = propertyInfo.GetValue(this) as double[];
                        if (array2 != null)
                        {
                            obj = array2.Cast <object>().ToArray <object>();
                        }
                    }
                    else if (propertyType == typeof(string[]))
                    {
                        string[] array3 = propertyInfo.GetValue(this) as string[];
                        if (array3 != null)
                        {
                            obj = array3.Cast <object>().ToArray <object>();
                        }
                    }
                    else if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(List <>))
                    {
                        IList list = propertyInfo.GetValue(this) as IList;
                        if (list != null)
                        {
                            object[] array4 = new object[list.Count];
                            list.CopyTo(array4, 0);
                            List <object> list2  = new List <object>();
                            object[]      array5 = array4;
                            for (int j = 0; j < array5.Length; j++)
                            {
                                object obj2  = array5[j];
                                Type   type2 = obj2.GetType();
                                if (typeof(RiotGamesObject).IsAssignableFrom(type2))
                                {
                                    RiotGamesObject riotGamesObject = obj2 as RiotGamesObject;
                                    obj = riotGamesObject.GetBaseTypedObject();
                                }
                                else
                                {
                                    obj = obj2;
                                }
                                list2.Add(obj);
                            }
                            obj = TypedObject.MakeArrayCollection(list2.ToArray());
                        }
                    }
                    else if (typeof(RiotGamesObject).IsAssignableFrom(propertyType))
                    {
                        RiotGamesObject riotGamesObject2 = propertyInfo.GetValue(this) as RiotGamesObject;
                        if (riotGamesObject2 != null)
                        {
                            obj = riotGamesObject2.GetBaseTypedObject();
                        }
                    }
                    else
                    {
                        obj = propertyInfo.GetValue(this);
                    }
                    typedObject.Add(internalNameAttribute.Name, obj);
                }
            }
            Type baseType = type.BaseType;

            if (baseType != null)
            {
                PropertyInfo[] properties2 = baseType.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                for (int k = 0; k < properties2.Length; k++)
                {
                    PropertyInfo          propertyInfo2          = properties2[k];
                    InternalNameAttribute internalNameAttribute2 = propertyInfo2.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault <object>() as InternalNameAttribute;
                    if (internalNameAttribute2 != null && !typedObject.ContainsKey(internalNameAttribute2.Name))
                    {
                        typedObject.Add(internalNameAttribute2.Name, propertyInfo2.GetValue(this));
                    }
                }
            }
            return(typedObject);
        }