protected virtual void Deserialize(SerializationInfo info, XmlFormatter formatter)
        {
            var currentType = GetType();

            while (currentType != null)
            {
                // get the list of fields in this type
                var fields = currentType.GetFields(
                    BindingFlags.NonPublic |
                    BindingFlags.Instance |
                    BindingFlags.Public);

                foreach (var field in fields)
                {
                    // see if this field is marked as not undoable
                    if (field.IsNotSerialized || IsNonSerialized(field))
                    {
                        continue;
                    }

                    var value = info.GetValue(string.Format("{0}!{1}", field.DeclaringType.Name, field.Name));
                    var valueInfo = value as SerializationInfo;
                    if (valueInfo == null)
                    {
                        SetValue(field, Convert.ChangeType(value, field.FieldType, null));
                    }
                    else
                    {
                        SetValue(field, formatter.GetObject(valueInfo.ReferenceId));
                    }
                }
                currentType = currentType.BaseType;
            }
        }
        protected virtual void Serialize(SerializationInfo info, XmlFormatter formatter)
        {
            var currentType = GetType();

            while (currentType != null)
            {
                var fields = currentType.GetFields(
                    BindingFlags.NonPublic |
                    BindingFlags.Instance |
                    BindingFlags.Public);

                foreach (var field in fields)
                {
                    if (field.IsNotSerialized || IsNonSerialized(field))
                    {
                        continue;
                    }

                    var value = GetValue(field);
                    var mobile = value as ISerializable;
                    info.AddValue(
                        string.Format("{0}!{1}", field.DeclaringType.Name, field.Name),
                        mobile == null ? value : formatter.SerializeObject(mobile)); 
                }
                currentType = currentType.BaseType;
            }
        }
        public object Deserialize(XmlReader reader)
        {
            var doc = XDocument.Load(reader);
            var root = (XElement) doc.FirstNode;

            _deserializationReferences.Clear();

            var objects = from e in root.Elements()
                          where e.Name == "o"
                          select e;

            var infos = new Dictionary<int, SerializationInfo>();

            foreach (var item in objects)
            {
                var info = new SerializationInfo(item);
                infos.Add(info.ReferenceId, info);
                var objType = Type.GetType(info.TypeName);
                var mobile = Activator.CreateInstance(objType) as ISerializable;
                _deserializationReferences.Add(info.ReferenceId, mobile);
            }

            foreach (var item in objects)
            {
                if (item == null)
                {
                    continue;
                }

                var referenceId = Convert.ToInt32(item.Attribute("i").Value);
                var info = infos[referenceId];
                info.Deserialize(item, this);
            }

            foreach (var info in infos)
            {
                GetObject(info.Value.ReferenceId).Deserialize(info.Value, this);
            }

            return _deserializationReferences[1];
        }
        internal SerializationInfo SerializeObject(object obj)
        {
            var thisType = obj.GetType();
            if (!IsSerializable(thisType))
            {
                throw new InvalidOperationException("Object not serializable");
            }
            var mobile = obj as ISerializable;
            if (mobile == null)
            {
                throw new InvalidOperationException(
                    string.Format("Type {0} must implement ISerializable",
                                  thisType.Name));
            }

            SerializationInfo info;
            if (!_serializationReferences.TryGetValue(mobile, out info))
            {
                info = new SerializationInfo(_serializationReferences.Count + 1);
                _serializationReferences.Add(mobile, info);
                mobile.Serialize(info, this);
            }
            return info;
        }
 void ISerializable.Deserialize(SerializationInfo info, XmlFormatter formatter)
 {
     Deserialize(info, formatter);
 }
 void ISerializable.Serialize(SerializationInfo info, XmlFormatter formatter)
 {
     var thisType = GetType();
     info.TypeName = string.Format("{0},{1}", thisType.FullName, thisType.Assembly.FullName);
     Serialize(info, formatter);
 }
Example #7
0
        /// <summary>
        /// Deserialization constructor 
        /// </summary>
        /// <param name="info"><see cref="System.Runtime.Serialization.SerializationInfo"/> for this constructor</param>
        protected GZipException(SerializationInfo info)
            : base(info)
        {

        }
 /// <summary>
 /// Deserialization constructor 
 /// </summary>
 /// <param name="information"><see cref="System.Runtime.Serialization.SerializationInfo"/> for this constructor</param>
 protected InvalidHeaderException(SerializationInfo information)
     : base(information)
 {
 }
 /// <summary>
 /// Deserialization constructor 
 /// </summary>
 /// <param name="info"><see cref="System.Runtime.Serialization.SerializationInfo"/> for this constructor</param>
 protected SharpZipBaseException(SerializationInfo info)
 {
 }
Example #10
0
 /// <summary>
 /// Deserialization constructor 
 /// </summary>
 /// <param name="info"><see cref="SerializationInfo"/> for this constructor</param>
 protected ZipException(SerializationInfo info)
 {
 }