コード例 #1
0
        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;
            }
        }
コード例 #2
0
        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;
            }
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
        void ISerializable.Serialize(SerializationInfo info, XmlFormatter formatter)
        {
            var thisType = GetType();

            info.TypeName = string.Format("{0},{1}", thisType.FullName, thisType.Assembly.FullName);
            Serialize(info, formatter);
        }
コード例 #5
0
        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;
            }
        }
コード例 #6
0
        internal void Deserialize(XElement data, XmlFormatter formatter)
        {
            foreach (var item in data.Elements())
            {
                if (item.Name == "f")
                {
                    var entry = new ValueEntry(item.Attribute("n").Value, item.Attribute("v").Value);
                    _values.Add(entry.Name, entry);
                }
                else if (item.Name == "l")
                {
                    var listItems = item.Elements().Select(content => new SerializationInfo(content)).ToList();

                    var entry = new ValueEntry(item.Attribute("n").Value, listItems);
                    _values.Add(entry.Name, entry);
                }
                else
                {
                    var referenceId = Convert.ToInt32(item.Attribute("i").Value);
                    var entry       = new ValueEntry(
                        item.Attribute("n").Value,
                        new SerializationInfo(referenceId));
                    _values.Add(entry.Name, entry);
                }
            }
        }
コード例 #7
0
 void ISerializable.Deserialize(SerializationInfo info, XmlFormatter formatter)
 {
     Deserialize(info, formatter);
 }
コード例 #8
0
 void ISerializable.Serialize(SerializationInfo info, XmlFormatter formatter)
 {
     var thisType = GetType();
     info.TypeName = string.Format("{0},{1}", thisType.FullName, thisType.Assembly.FullName);
     Serialize(info, formatter);
 }
コード例 #9
0
 void ISerializable.Deserialize(SerializationInfo info, XmlFormatter formatter)
 {
     Deserialize(info, formatter);
 }
コード例 #10
0
        internal void Deserialize(XElement data, XmlFormatter formatter)
        {
            foreach (var item in data.Elements())
            {
                if (item.Name == "f")
                {
                    var entry = new ValueEntry(item.Attribute("n").Value, item.Attribute("v").Value);
                    _values.Add(entry.Name, entry);
                }
                else if (item.Name == "l")
                {
                    var listItems = item.Elements().Select(content => new SerializationInfo(content)).ToList();

                    var entry = new ValueEntry(item.Attribute("n").Value, listItems);
                    _values.Add(entry.Name, entry);
                }
                else
                {
                    var referenceId = Convert.ToInt32(item.Attribute("i").Value);
                    var entry = new ValueEntry(
                        item.Attribute("n").Value, 
                        new SerializationInfo(referenceId));
                    _values.Add(entry.Name, entry);
                }
            }
        }
コード例 #11
0
ファイル: ZipTests.cs プロジェクト: modulexcite/graveyard
        private ISerializable UnZipZeroLength(byte[] zipped)
        {
            if (zipped == null)
            {
                return null;
            }

            object result = null;
            var formatter = new XmlFormatter();
            var memStream = new MemoryStream(zipped);
            using (var zipStream = new ZipInputStream(memStream))
            {
                var zipEntry = zipStream.GetNextEntry();
                if (zipEntry != null)
                {
                    result = formatter.Deserialize(zipStream);
                }
                zipStream.Close();
            }
            memStream.Close();

            return (ISerializable)result;
        }
コード例 #12
0
ファイル: ZipTests.cs プロジェクト: modulexcite/graveyard
        private byte[] ZipZeroLength(ISerializable data)
        {
            var formatter = new XmlFormatter();
            var memStream = new MemoryStream();

            using (var zipStream = new ZipOutputStream(memStream))
            {
                zipStream.PutNextEntry(new ZipEntry("data"));
                formatter.Serialize(zipStream, data);
                zipStream.CloseEntry();
                zipStream.Close();
            }

            var result = memStream.ToArray();
            memStream.Close();

            return result;
        }