Ejemplo n.º 1
0
        public IDictionary ReadMap <T>(ref T map)
        {
            IDictionary dictionary = BasicClassTypeUtil.CreateObject(map.GetType()) as IDictionary;

            if (dictionary == null)
            {
                return(null);
            }
            dictionary.Clear();
            int num = 0;

            this.Read(ref num);
            if (num <= 0)
            {
                return(null);
            }
            Type type = dictionary.GetType();

            Type[] genericArguments = type.GetGenericArguments();
            if (genericArguments == null || genericArguments.Length < 2)
            {
                return(null);
            }
            for (int i = 0; i < num; i++)
            {
                object obj  = BasicClassTypeUtil.CreateObject(genericArguments[0]);
                object obj2 = BasicClassTypeUtil.CreateObject(genericArguments[1]);
                obj  = this.Read <object>(ref obj);
                obj2 = this.Read <object>(ref obj2);
                dictionary.Add(obj, obj2);
            }
            map = (T)((object)dictionary);
            return(dictionary);
        }
Ejemplo n.º 2
0
        public IDictionary ReadMap <T>(ref T map)
        {
            IDictionary dictionary = BasicClassTypeUtil.CreateObject(map.GetType()) as IDictionary;

            if (dictionary == null)
            {
                return(null);
            }
            dictionary.Clear();
            int v = 0;

            this.Read(ref v);
            if (v <= 0)
            {
                return(null);
            }
            Type[] genericArguments = dictionary.GetType().GetGenericArguments();
            if ((genericArguments == null) || (genericArguments.Length < 2))
            {
                return(null);
            }
            for (int i = 0; i < v; i++)
            {
                object o    = BasicClassTypeUtil.CreateObject(genericArguments[0]);
                object obj3 = BasicClassTypeUtil.CreateObject(genericArguments[1]);
                o    = this.Read <object>(ref o);
                obj3 = this.Read <object>(ref obj3);
                dictionary.Add(o, obj3);
            }
            map = (T)dictionary;
            return(dictionary);
        }
Ejemplo n.º 3
0
 public static object CreateListItem(Type typeList)
 {
     Type[] genericArguments = typeList.GetGenericArguments();
     if (genericArguments == null || genericArguments.Length == 0)
     {
         return(null);
     }
     return(BasicClassTypeUtil.CreateObject(genericArguments[0]));
 }
Ejemplo n.º 4
0
        public IList ReadList <T>(ref T l)
        {
            int num = 0;

            this.Read(ref num);
            IList list = l as IList;

            if (list == null)
            {
                ADebug.LogError("ReadList list == null");
                return(null);
            }
            list.Clear();
            for (int i = 0; i < num; i++)
            {
                object obj = BasicClassTypeUtil.CreateListItem(list.GetType());
                this.Read <object>(ref obj);
                list.Add(obj);
            }
            return(list);
        }
Ejemplo n.º 5
0
 public object Read <T>(ref T o)
 {
     if (o == null)
     {
         o = (T)((object)BasicClassTypeUtil.CreateObject <T>());
     }
     if (o is byte || o is char)
     {
         byte b = 0;
         o = (T)((object)this.Read(ref b));
     }
     else if (o is char)
     {
         byte b2 = 0;
         o = (T)((object)this.Read(ref b2));
     }
     else if (o is bool)
     {
         bool flag = false;
         o = (T)((object)this.Read(ref flag));
     }
     else if (o is short)
     {
         short num = 0;
         o = (T)((object)this.Read(ref num));
     }
     else if (o is ushort)
     {
         ushort num2 = 0;
         o = (T)((object)this.Read(ref num2));
     }
     else if (o is int)
     {
         int num3 = 0;
         o = (T)((object)this.Read(ref num3));
     }
     else
     {
         if (o is uint)
         {
             uint num4 = 0u;
             o = (T)((object)this.Read(ref num4));
             return(o);
         }
         if (o is long)
         {
             long num5 = 0L;
             o = (T)((object)this.Read(ref num5));
             return(o);
         }
         if (o is Enum)
         {
             int num6 = 0;
             o = (T)((object)this.Read(ref num6));
             return(o);
         }
         if (o is ulong)
         {
             ulong  num7 = 0uL;
             object obj  = this.Read(ref num7);
             o = (T)((object)obj);
             return(obj);
         }
         if (o is string)
         {
             string empty = string.Empty;
             o = (T)((object)this.Read(ref empty));
         }
         else if (o is ApolloBufferBase)
         {
             ApolloBufferBase apolloBufferBase = o as ApolloBufferBase;
             o = (T)((object)this.Read(ref apolloBufferBase));
         }
         else if (o == null || !o.GetType().get_IsArray())
         {
             if (o is IList)
             {
                 return(this.ReadList <T>(ref o));
             }
             if (o is IDictionary)
             {
                 return(this.ReadMap <T>(ref o));
             }
             throw new Exception(string.Concat(new object[]
             {
                 "read object error: unsupport type:",
                 o.GetType(),
                 " value:",
                 o.ToString()
             }));
         }
     }
     return(o);
 }
Ejemplo n.º 6
0
 public static object CreateObject <T>()
 {
     return(BasicClassTypeUtil.CreateObject(typeof(T)));
 }
Ejemplo n.º 7
0
 public object Read <T>(ref T o)
 {
     if (((T)o) == null)
     {
         o = (T)BasicClassTypeUtil.CreateObject <T>();
     }
     if ((((T)o) is byte) || (((T)o) is char))
     {
         byte c = 0;
         o = (T)this.Read(ref c);
     }
     else if (((T)o) is char)
     {
         byte num2 = 0;
         o = (T)this.Read(ref num2);
     }
     else if (((T)o) is bool)
     {
         bool b = false;
         o = (T)this.Read(ref b);
     }
     else if (((T)o) is short)
     {
         short v = 0;
         o = (T)this.Read(ref v);
     }
     else if (((T)o) is ushort)
     {
         ushort num4 = 0;
         o = (T)this.Read(ref num4);
     }
     else if (((T)o) is int)
     {
         int num5 = 0;
         o = (T)this.Read(ref num5);
     }
     else
     {
         if (((T)o) is uint)
         {
             uint num6 = 0;
             o = (T)this.Read(ref num6);
             return((T)o);
         }
         if (((T)o) is long)
         {
             long num7 = 0L;
             o = (T)this.Read(ref num7);
             return((T)o);
         }
         if (((T)o) is Enum)
         {
             int num8 = 0;
             o = (T)this.Read(ref num8);
             return((T)o);
         }
         if (((T)o) is ulong)
         {
             ulong  num9 = 0L;
             object obj2 = this.Read(ref num9);
             o = (T)obj2;
             return(obj2);
         }
         if (((T)o) is string)
         {
             string s = string.Empty;
             o = (T)this.Read(ref s);
         }
         else if (((T)o) is ApolloBufferBase)
         {
             ApolloBufferBase ab = ((T)o) as ApolloBufferBase;
             o = (T)this.Read(ref ab);
         }
         else if ((((T)o) == null) || !o.GetType().IsArray)
         {
             if (((T)o) is IList)
             {
                 return(this.ReadList <T>(ref o));
             }
             if (((T)o) is IDictionary)
             {
                 return(this.ReadMap <T>(ref o));
             }
             object[] objArray1 = new object[] { "read object error: unsupport type:", o.GetType(), " value:", o.ToString() };
             throw new Exception(string.Concat(objArray1));
         }
     }
     return((T)o);
 }