Exemple #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>
        /// <param name="formatter">Reference to the current MobileFormatter.</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);
                }
            }
        }
Exemple #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>
        /// <param name="formatter">Reference to the current MobileFormatter.</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());
                }
            }
        }
 /// <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>
 /// <param name="formatter">
 /// Reference to MobileFormatter instance. Use this to
 /// convert child references to/from reference id values.
 /// </param>
 protected virtual void OnMobileDeserializeRef(ISerializationContext context)
 {
     FieldsSerializationHelper.DeserialzeFields(this, context);
 }
 /// <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>
 /// <param name="e">
 /// The StateMode indicating why this method was invoked.
 /// </param>
 protected virtual void OnMobileSerializeState(ISerializationContext context)
 {
     FieldsSerializationHelper.SerialzeFields(this, context);
 }
Exemple #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);
 }