Пример #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);
        }
Пример #2
0
        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);
        }
Пример #3
0
 public void SetFields <T>(T obj, TypedObject result)
 {
     if (result != null)
     {
         this.TypeName = result.type;
         foreach (PropertyInfo info in typeof(T).GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
         {
             InternalNameAttribute attribute = info.GetCustomAttributes(typeof(InternalNameAttribute), false).FirstOrDefault <object>() as InternalNameAttribute;
             if (attribute != null)
             {
                 object obj2;
                 Type   propertyType = info.PropertyType;
                 if (result.TryGetValue(attribute.Name, out obj2))
                 {
                     try
                     {
                         if (result[attribute.Name] == null)
                         {
                             obj2 = null;
                         }
                         else if (propertyType == typeof(string))
                         {
                             obj2 = Convert.ToString(result[attribute.Name]);
                         }
                         else if (propertyType == typeof(int))
                         {
                             obj2 = Convert.ToInt32(result[attribute.Name]);
                         }
                         else if (propertyType == typeof(long))
                         {
                             obj2 = Convert.ToInt64(result[attribute.Name]);
                         }
                         else if (propertyType == typeof(double))
                         {
                             obj2 = Convert.ToInt64(result[attribute.Name]);
                         }
                         else if (propertyType == typeof(bool))
                         {
                             obj2 = Convert.ToBoolean(result[attribute.Name]);
                         }
                         else if (propertyType == typeof(DateTime))
                         {
                             obj2 = result[attribute.Name];
                         }
                         else if (propertyType == typeof(TypedObject))
                         {
                             obj2 = (TypedObject)result[attribute.Name];
                         }
                         else if (propertyType.IsGenericType && (propertyType.GetGenericTypeDefinition() == typeof(List <>)))
                         {
                             object[] array         = result.GetArray(attribute.Name);
                             Type     type          = propertyType.GetGenericArguments()[0];
                             Type[]   typeArguments = new Type[] { type };
                             IList    list          = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(typeArguments));
                             foreach (object obj3 in array)
                             {
                                 if (obj3 == null)
                                 {
                                     list.Add(null);
                                 }
                                 if (type == typeof(string))
                                 {
                                     list.Add((string)obj3);
                                 }
                                 else if (type == typeof(Participant))
                                 {
                                     TypedObject obj4 = (TypedObject)obj3;
                                     if (obj4.type == "com.riotgames.platform.game.BotParticipant")
                                     {
                                         list.Add(new BotParticipant(obj4));
                                     }
                                     else if (obj4.type == "com.riotgames.platform.game.ObfruscatedParticipant")
                                     {
                                         list.Add(new ObfruscatedParticipant(obj4));
                                     }
                                     else if (obj4.type == "com.riotgames.platform.game.PlayerParticipant")
                                     {
                                         list.Add(new PlayerParticipant(obj4));
                                     }
                                     else if (obj4.type == "com.riotgames.platform.reroll.pojo.AramPlayerParticipant")
                                     {
                                         list.Add(new AramPlayerParticipant(obj4));
                                     }
                                 }
                                 else if (type == typeof(int))
                                 {
                                     list.Add((int)obj3);
                                 }
                                 else
                                 {
                                     object[] args = new object[] { obj3 };
                                     list.Add(Activator.CreateInstance(type, args));
                                 }
                             }
                             obj2 = list;
                         }
                         else if (propertyType == typeof(Dictionary <string, object>))
                         {
                             obj2 = (Dictionary <string, object>)result[attribute.Name];
                         }
                         else if (propertyType.IsGenericType && (propertyType.GetGenericTypeDefinition() == typeof(Dictionary <,>)))
                         {
                             obj2 = (Dictionary <string, object>)result[attribute.Name];
                         }
                         else if (propertyType == typeof(int[]))
                         {
                             obj2 = result.GetArray(attribute.Name).Cast <int>().ToArray <int>();
                         }
                         else if (propertyType == typeof(string[]))
                         {
                             obj2 = result.GetArray(attribute.Name).Cast <string>().ToArray <string>();
                         }
                         else if (propertyType == typeof(object[]))
                         {
                             obj2 = result.GetArray(attribute.Name);
                         }
                         else if (propertyType == typeof(object))
                         {
                             obj2 = result[attribute.Name];
                         }
                         else
                         {
                             try
                             {
                                 object[] objArray3 = new object[] { result[attribute.Name] };
                                 obj2 = Activator.CreateInstance(propertyType, objArray3);
                             }
                             catch (Exception exception)
                             {
                                 throw new NotSupportedException(string.Format("Type {0} not supported by flash serializer", propertyType.FullName), exception);
                             }
                         }
                         info.SetValue(obj, obj2, null);
                     }
                     catch
                     {
                     }
                 }
             }
         }
     }
 }
Пример #4
0
 public void SetFields <T>(T obj, TypedObject result)
 {
     if (result == null)
     {
         return;
     }
     this.TypeName = result.type;
     PropertyInfo[] properties = typeof(T).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)
         {
             Type   propertyType = propertyInfo.PropertyType;
             object value;
             if (result.TryGetValue(internalNameAttribute.Name, out value))
             {
                 try
                 {
                     if (result[internalNameAttribute.Name] == null)
                     {
                         value = null;
                     }
                     else if (propertyType == typeof(string))
                     {
                         value = Convert.ToString(result[internalNameAttribute.Name]);
                     }
                     else if (propertyType == typeof(int))
                     {
                         value = Convert.ToInt32(result[internalNameAttribute.Name]);
                     }
                     else if (propertyType == typeof(long))
                     {
                         value = Convert.ToInt64(result[internalNameAttribute.Name]);
                     }
                     else if (propertyType == typeof(double))
                     {
                         value = Convert.ToInt64(result[internalNameAttribute.Name]);
                     }
                     else if (propertyType == typeof(bool))
                     {
                         value = Convert.ToBoolean(result[internalNameAttribute.Name]);
                     }
                     else if (propertyType == typeof(DateTime))
                     {
                         value = result[internalNameAttribute.Name];
                     }
                     else if (propertyType == typeof(TypedObject))
                     {
                         value = (TypedObject)result[internalNameAttribute.Name];
                     }
                     else if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(List <>))
                     {
                         object[] array = result.GetArray(internalNameAttribute.Name);
                         Type     type  = propertyType.GetGenericArguments()[0];
                         Type     type2 = typeof(List <>).MakeGenericType(new Type[]
                         {
                             type
                         });
                         IList    list   = (IList)Activator.CreateInstance(type2);
                         object[] array2 = array;
                         for (int j = 0; j < array2.Length; j++)
                         {
                             object obj2 = array2[j];
                             if (obj2 == null)
                             {
                                 list.Add(null);
                             }
                             if (type == typeof(string))
                             {
                                 list.Add((string)obj2);
                             }
                             else if (type == typeof(Participant))
                             {
                                 TypedObject typedObject = (TypedObject)obj2;
                                 if (typedObject.type == "com.riotgames.platform.game.BotParticipant")
                                 {
                                     list.Add(new BotParticipant(typedObject));
                                 }
                                 else if (typedObject.type == "com.riotgames.platform.game.ObfruscatedParticipant")
                                 {
                                     list.Add(new ObfruscatedParticipant(typedObject));
                                 }
                                 else if (typedObject.type == "com.riotgames.platform.game.PlayerParticipant")
                                 {
                                     list.Add(new PlayerParticipant(typedObject));
                                 }
                                 else if (typedObject.type == "com.riotgames.platform.reroll.pojo.AramPlayerParticipant")
                                 {
                                     list.Add(new AramPlayerParticipant(typedObject));
                                 }
                             }
                             else if (type == typeof(int))
                             {
                                 list.Add((int)obj2);
                             }
                             else
                             {
                                 list.Add(Activator.CreateInstance(type, new object[]
                                 {
                                     obj2
                                 }));
                             }
                         }
                         value = list;
                     }
                     else if (propertyType == typeof(Dictionary <string, object>))
                     {
                         Dictionary <string, object> dictionary = (Dictionary <string, object>)result[internalNameAttribute.Name];
                         value = dictionary;
                     }
                     else if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Dictionary <, >))
                     {
                         Dictionary <string, object> dictionary2 = (Dictionary <string, object>)result[internalNameAttribute.Name];
                         value = dictionary2;
                     }
                     else if (propertyType == typeof(int[]))
                     {
                         value = result.GetArray(internalNameAttribute.Name).Cast <int>().ToArray <int>();
                     }
                     else if (propertyType == typeof(string[]))
                     {
                         value = result.GetArray(internalNameAttribute.Name).Cast <string>().ToArray <string>();
                     }
                     else if (propertyType == typeof(object[]))
                     {
                         value = result.GetArray(internalNameAttribute.Name);
                     }
                     else if (propertyType == typeof(object))
                     {
                         value = result[internalNameAttribute.Name];
                     }
                     else
                     {
                         try
                         {
                             value = Activator.CreateInstance(propertyType, new object[]
                             {
                                 result[internalNameAttribute.Name]
                             });
                         }
                         catch (Exception innerException)
                         {
                             throw new NotSupportedException(string.Format("Type {0} not supported by flash serializer", propertyType.FullName), innerException);
                         }
                     }
                     propertyInfo.SetValue(obj, value, null);
                 }
                 catch
                 {
                 }
             }
         }
     }
 }