public static VersionedXmlBase ParseFromBase64(string base64)
        {
            if (string.IsNullOrEmpty(base64))
            {
                throw new CustomSerializationException(ServerStrings.ErrorInvalidConfigurationXml, new ArgumentNullException("base64"));
            }
            VersionedXmlBase result;

            using (MemoryStream memoryStream = new MemoryStream(Convert.FromBase64String(base64)))
            {
                result = VersionedXmlBase.Deserialize(memoryStream);
            }
            return(result);
        }
        public static VersionedXmlBase Parse(string xml)
        {
            if (string.IsNullOrEmpty(xml))
            {
                throw new CustomSerializationException(ServerStrings.ErrorInvalidConfigurationXml, new ArgumentNullException("xml"));
            }
            VersionedXmlBase result;

            using (MemoryStream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
            {
                result = VersionedXmlBase.Deserialize(memoryStream);
            }
            return(result);
        }
        private static string GetXmlString(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            string @string;

            using (MemoryStream memoryStream = new MemoryStream())
            {
                VersionedXmlBase.Serialize(memoryStream, obj);
                memoryStream.Seek(0L, SeekOrigin.Begin);
                @string = Encoding.UTF8.GetString(memoryStream.ToArray());
            }
            return(@string);
        }
        private static string GetBase64XmlString(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            string result;

            using (MemoryStream memoryStream = new MemoryStream())
            {
                VersionedXmlBase.Serialize(memoryStream, obj);
                memoryStream.Seek(0L, SeekOrigin.Begin);
                result = Convert.ToBase64String(memoryStream.ToArray());
            }
            return(result);
        }
 internal static void Serialize(Stream stream, VersionedXmlBase obj)
 {
     if (stream == null)
     {
         throw new CustomSerializationException(ServerStrings.ErrorInvalidConfigurationXml, new ArgumentNullException("stream"));
     }
     if (obj == null)
     {
         throw new ArgumentNullException("obj");
     }
     VersionedXmlBase.Serialize(stream, obj);
     try
     {
         stream.SetLength(stream.Position);
     }
     catch (NotSupportedException)
     {
     }
 }
        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));
        }
 public string ToBase64String()
 {
     return(VersionedXmlBase.GetBase64XmlString(this));
 }
 public override string ToString()
 {
     return(VersionedXmlBase.GetXmlString(this));
 }