示例#1
0
        /// <summary>
        /// Override this method to manually deserialize child objects
        /// from data in the serialization stream.
        /// </summary>
        /// <param name="info">Object containing serialized values.</param>
        protected virtual void OnDeserializeRef(ISerializationContext info)
        {
            FieldsSerializationHelper.DeserialzeFields(this, info);

            bool mobileChildren = typeof(IMobileObject).IsAssignableFrom(typeof(T));

            if (mobileChildren)
            {
                var formatter  = info.RefFormatter;
                var references = info.GetState <object[]>("$list");
                if (references != null)
                {
                    foreach (int reference in references)
                    {
                        T child = (T)formatter.GetObject(reference);
                        this.Add(child);
                    }
                }
            }
            else
            {
                var bufferObj = info.GetState <object[]>("$list");

                var buffer = new byte[bufferObj.Length];
                for (int i = 0, c = bufferObj.Length; i < c; i++)
                {
                    buffer[i] = (byte)(int)bufferObj[i];
                }

                using (MemoryStream stream = new MemoryStream(buffer))
                {
                    var            dcs  = new serialization.DataContractSerializer(GetType());
                    MobileList <T> list = (MobileList <T>)dcs.ReadObject(stream);
                    AddRange(list);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Override this method to manually serialize child objects
        /// contained within the current object.
        /// </summary>
        /// <param name="info">Object containing serialized values.</param>
        protected virtual void OnSerializeRef(ISerializationContext info)
        {
            FieldsSerializationHelper.SerialzeFields(this, info);

            bool mobileChildren = typeof(IMobileObject).IsAssignableFrom(typeof(T));

            if (mobileChildren)
            {
                var formatter = info.RefFormatter;

                var references = new List <int>(this.Count);
                for (int x = 0; x < this.Count; x++)
                {
                    T child = this[x];
                    if (child != null)
                    {
                        var childInfo = formatter.SerializeObject(child);
                        references.Add(childInfo.ReferenceId);
                    }
                }

                if (references.Count > 0)
                {
                    info.AddState("$list", references);
                }
            }
            else
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    serialization.DataContractSerializer serializer = new serialization.DataContractSerializer(GetType());
                    serializer.WriteObject(stream, this);
                    stream.Flush();
                    info.AddState("$list", stream.ToArray());
                }
            }
        }
示例#3
0
 /// <summary>
 /// Override this method to retrieve your child object
 /// references from the MobileFormatter serialzation stream.
 /// </summary>
 /// <param name="context">Object containing the data to serialize.</param>
 protected virtual void OnMobileDeserializeRef(ISerializationContext context)
 {
     FieldsSerializationHelper.DeserialzeFields(this, context);
 }
示例#4
0
 /// <summary>
 /// Override this method to insert your field values
 /// into the MobileFormatter serialzation stream.
 /// </summary>
 /// <param name="context">Object containing the data to serialize.</param>
 protected virtual void OnMobileSerializeState(ISerializationContext context)
 {
     FieldsSerializationHelper.SerialzeFields(this, context);
 }
示例#5
0
 /// <summary>
 /// Override this method to retrieve extra field values to
 /// the serialization stream.
 /// </summary>
 /// <param name="info">Object containing field values.</param>
 protected virtual void OnDeserializeState(ISerializationContext info)
 {
     FieldsSerializationHelper.DeserialzeFields(this, info);
 }