Пример #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 (ServerSide)
            {
                ((TLObject)obj).DeserializeBody(reader);
                return(obj);
            }

            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);
            }
        }