protected override object ReadBody(TLSerializationContext context)
        {
            object obj = Activator.CreateInstance(_objectType);

            for (int i = 0; i < _properties.Length; i++)
            {
                TLPropertyInfo tlPropertyInfo = _properties[i];
                PropertyInfo   propertyInfo   = tlPropertyInfo.PropertyInfo;

                object propertyValue;

                Type propType = propertyInfo.PropertyType;

                ITLSerializer tlSerializer = context.Rig.GetSerializerByObjectType(propType);

                if (tlSerializer is ITLVectorSerializer)
                {
                    var vectorSerializer = tlSerializer as ITLVectorSerializer;
                    TLSerializationMode?itemsSerializationModeOverride = GetVectorItemsSerializationModeOverride(vectorSerializer, propertyInfo, context);
                    propertyValue = vectorSerializer.Read(context, tlPropertyInfo.SerializationModeOverride, itemsSerializationModeOverride);
                }
                else
                {
                    propertyValue = tlSerializer.Read(context, tlPropertyInfo.SerializationModeOverride);
                }
                tlPropertyInfo.PropertyInfo.SetValue(obj, propertyValue);
            }
            return(obj);
        }
示例#2
0
        /// <summary>
        ///     Deserialize an object from TL serialization context.
        /// </summary>
        /// <remarks>
        ///     Constructor number for the object is automatically determined by reading the first number from the streamer,
        ///     hence object within the context streamer must be serialized as boxed type.
        /// </remarks>
        /// <param name="context">TL serialization context.</param>
        /// <returns>Deserialized object.</returns>
        /// <exception cref="TLSerializerNotFoundException">When serializer not found.</exception>
        public static object Deserialize(TLSerializationContext context)
        {
            // Here streamer's position must point to a boxed TL type.
            TLStreamer streamer = context.Streamer;

            // Read a constructor number and restore the streamer position.
            streamer.PushPosition();
            uint constructorNumber = streamer.ReadUInt32();

            //Console.WriteLine("Retrived constructor number " + constructorNumber);
            streamer.PopPosition();

            ITLSerializer serializer = context.Rig.GetSerializerByConstructorNumber(constructorNumber);



            //Console.WriteLine("Got serializer for above constructor number" + serializer.SupportedType);



            if (serializer == null)
            {
                throw new TLSerializerNotFoundException(
                          string.Format("Constructor number: 0x{0:X8} is not supported by any registered serializer.", constructorNumber));
            }

            return(serializer.Read(context, TLSerializationMode.Boxed));
        }
示例#3
0
        /// <summary>
        ///     Deserialize an object from TL serialization context.
        /// </summary>
        /// <param name="objType">Type of the object.</param>
        /// <param name="context">TL serialization context.</param>
        /// <param name="modeOverride">Serialization mode override.</param>
        /// <returns>Deserialized object.</returns>
        /// <exception cref="TLSerializerNotFoundException">When serializer not found.</exception>
        public static object Deserialize(Type objType, TLSerializationContext context, TLSerializationMode?modeOverride = null)
        {
            if (objType == typeof(object))
            {
                return(Deserialize(context));
            }

            ITLSerializer serializer = context.Rig.GetSerializerByObjectType(objType);

            if (serializer == null)
            {
                throw new TLSerializerNotFoundException(string.Format("There is no serializer for a type: '{0}'.", objType.FullName));
            }
            return(serializer.Read(context, modeOverride));
        }
示例#4
0
文件: TLRig.cs 项目: andri-ys/SharpTL
        /// <summary>
        ///     Deserialize an object from TL serialization context.
        /// </summary>
        /// <remarks>
        ///     Constructor number for the object is automatically determined by reading the first number from the streamer,
        ///     hence object within the context streamer must be serialized as boxed type.
        /// </remarks>
        /// <param name="context">TL serialization context.</param>
        /// <returns>Deserialized object.</returns>
        /// <exception cref="TLSerializerNotFoundException">When serializer not found.</exception>
        public static object Deserialize(TLSerializationContext context)
        {
            TLStreamer streamer = context.Streamer;

            // Read a constructor number.
            uint          constructorNumber = streamer.ReadUInt32();
            ITLSerializer serializer        = context.Rig.GetSerializerByConstructorNumber(constructorNumber);

            if (serializer == null)
            {
                throw new TLSerializerNotFoundException(string.Format("Constructor number: 0x{0:X8} is not supported by any registered serializer.", constructorNumber));
            }

            // Bare because construction number has already been read.
            return(serializer.Read(context, TLSerializationMode.Bare));
        }
示例#5
0
 protected override object ReadValue(TLSerializationContext context)
 {
     return(_serializer.Read(context, TLPropertyInfo.SerializationModeOverride));
 }