getType() public static method

public static getType ( int Constructor ) : Type
Constructor int
return System.Type
Beispiel #1
0
        public static object DeserializeObject(BinaryReader reader)
        {
            int    Constructor = reader.ReadInt32();
            object obj;
            Type   t = null;

            try
            {
                t   = TLContext.getType(Constructor);
                obj = Activator.CreateInstance(t);
            }
            catch (Exception ex)
            {
                throw new InvalidDataException("Constructor Invalid Or Context.Init Not Called !", ex);
            }
            if (t.IsSubclassOf(typeof(TLMethod)))
            {
                ((TLMethod)obj).DeserializeResponse(reader);
                return(obj);
            }
            else if (t.IsSubclassOf(typeof(TLObject)))
            {
                ((TLObject)obj).DeserializeBody(reader);
                return(obj);
            }
            else
            {
                throw new NotImplementedException("Weird Type : " + t.Namespace + " | " + t.Name);
            }
        }
Beispiel #2
0
        public override void DeserializeBody(BinaryReader br)
        {
            int count = br.ReadInt32();

            for (var i = 0; i < count; i++)
            {
                if (typeof(T) == typeof(int))
                {
                    lists.Add((T)Convert.ChangeType(br.ReadInt32(), typeof(T)));
                }
                else if (typeof(T) == typeof(long))
                {
                    lists.Add((T)Convert.ChangeType(br.ReadInt64(), typeof(T)));
                }
                else if (typeof(T) == typeof(string))
                {
                    lists.Add((T)Convert.ChangeType(StringUtil.Deserialize(br), typeof(T)));
                }
                else if (typeof(T) == typeof(double))
                {
                    lists.Add((T)Convert.ChangeType(br.ReadDouble(), typeof(T)));
                }
                else if (typeof(T).BaseType == typeof(TLObject))
                {
                    int    constructor = br.ReadInt32();
                    Type   type        = TLContext.getType(constructor);
                    object obj         = Activator.CreateInstance(type);
                    type.GetMethod("DeserializeBody").Invoke(obj, new object[] { br });
                    lists.Add((T)Convert.ChangeType(obj, type));
                }
            }
        }