コード例 #1
0
        internal static VersionedXmlBase Deserialize(Stream stream)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (!stream.CanSeek)
            {
                throw new ArgumentException("stream");
            }
            long position = stream.Position;
            XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();

            xmlReaderSettings.ConformanceLevel = ConformanceLevel.Auto;
            string  text    = null;
            Version version = null;

            using (XmlReader xmlReader = XmlReader.Create(stream, xmlReaderSettings))
            {
                while (xmlReader.Read())
                {
                    if (XmlNodeType.Element == xmlReader.NodeType)
                    {
                        text = xmlReader.Name;
                        string attribute = xmlReader.GetAttribute("Version");
                        if (!string.IsNullOrEmpty(attribute))
                        {
                            version = new Version(attribute);
                            break;
                        }
                        break;
                    }
                }
            }
            if (string.IsNullOrEmpty(text) || null == version)
            {
                return(null);
            }
            stream.Seek(position, SeekOrigin.Begin);
            return((VersionedXmlBase)VersionedXmlBase.Deserialize(VersionedXmlTypeFactory.GetTypeInstance(text, version), stream));
        }
コード例 #2
0
        private static object Deserialize(Type type, Stream stream)
        {
            XmlReaderSettings xmlReaderSettings = null;
            XmlSchema         xmlSchema         = null;
            XmlSerializer     xmlSerializer     = VersionedXmlTypeFactory.GetXmlSerializer(type, out xmlSchema);

            if (xmlSchema != null)
            {
                xmlReaderSettings = new XmlReaderSettings();
                xmlReaderSettings.ValidationType  = ValidationType.Schema;
                xmlReaderSettings.ValidationFlags = (XmlSchemaValidationFlags.ProcessInlineSchema | XmlSchemaValidationFlags.ProcessSchemaLocation | XmlSchemaValidationFlags.ReportValidationWarnings | XmlSchemaValidationFlags.ProcessIdentityConstraints | XmlSchemaValidationFlags.AllowXmlAttributes);
                xmlReaderSettings.Schemas.Add(xmlSchema);
            }
            object result;

            using (XmlReader xmlReader = XmlReader.Create(stream, xmlReaderSettings))
            {
                result = xmlSerializer.Deserialize(xmlReader);
            }
            return(result);
        }
コード例 #3
0
 private static void Serialize(Stream stream, object obj)
 {
     VersionedXmlTypeFactory.GetXmlSerializer(obj.GetType()).Serialize(stream, obj);
 }
コード例 #4
0
        public static XmlSerializer GetXmlSerializer(Type type)
        {
            XmlSchema xmlSchema = null;

            return(VersionedXmlTypeFactory.GetXmlSerializer(type, out xmlSchema));
        }