コード例 #1
0
        public SerializedObject DeserializeFromByteArray(byte[] bytData)
        {
            if (bytData == null)
            {
                throw new ArgumentNullException("bytData", "A valid non-null byte[] is required.");
            }

            XmlLiteDocument objXmlDocument = null;

            using (MemoryStream objMemoryStream = new MemoryStream(bytData))
            {
                objXmlDocument = XmlLiteDocument.LoadFromStream(objMemoryStream);
            }

            XmlLiteElement objXmlElement = objXmlDocument.Root;

            bool   blnContainsAttribute = objXmlElement.Attributes.Exists(AssemblyAttributeName);
            string strAssemblyName      = ((blnContainsAttribute == true) ? objXmlElement.Attributes[AssemblyAttributeName].Value : string.Empty);

            blnContainsAttribute = objXmlElement.Attributes.Exists(TypeAttributeName);
            string strTypeName = ((blnContainsAttribute == true) ? objXmlElement.Attributes[TypeAttributeName].Value : string.Empty);

            SerializedObject objSerializedObject = new SerializedObject(objXmlElement.Name, new SerializedTypeInfo(strTypeName, strAssemblyName));

            Deserialize(objXmlElement, objSerializedObject);

            return(objSerializedObject);
        }
コード例 #2
0
        public SerializedObject DeserializeFromFile(string strFilePath)
        {
            if (strFilePath == null)
            {
                throw new ArgumentNullException("strFilePath", "A valid non-null string is required.");
            }
            if (FileManager.Exists(strFilePath) == false)
            {
                throw new FileNotFoundException("The file to be deserialized does not exist.", strFilePath);
            }

            XmlLiteDocument objXmlDocument = XmlLiteDocument.LoadFromFile(strFilePath);
            XmlLiteElement  objXmlElement  = objXmlDocument.Root;

            bool   blnContainsAttribute = objXmlElement.Attributes.Exists(AssemblyAttributeName);
            string strAssemblyName      = ((blnContainsAttribute == true) ? objXmlElement.Attributes[AssemblyAttributeName].Value : string.Empty);

            blnContainsAttribute = objXmlElement.Attributes.Exists(TypeAttributeName);
            string strTypeName = ((blnContainsAttribute == true) ? objXmlElement.Attributes[TypeAttributeName].Value : string.Empty);

            SerializedObject objSerializedObject = new SerializedObject(objXmlElement.Name, new SerializedTypeInfo(strTypeName, strAssemblyName));

            Deserialize(objXmlElement, objSerializedObject);

            return(objSerializedObject);
        }
コード例 #3
0
        public WebDAVFileProperties(string strRawResponse)
        {
            if (string.IsNullOrEmpty(strRawResponse) == true)
            {
                throw new ArgumentOutOfRangeException("strRawResponse", "A valid non-null, non-empty string is required.");
            }

            XmlLiteDocument objXmlLiteDocument = XmlLiteDocument.LoadFromXml(strRawResponse);

            XmlLiteElement objResponseElement = objXmlLiteDocument.Root.Elements.GetElement("response");

            if (objResponseElement == null)
            {
                throw new Exception("Unable to locate the child element 'response'.");
            }

            XmlLiteElement objHrefElement = objResponseElement.Elements.GetElement("href");

            if (objHrefElement == null)
            {
                throw new Exception("Unable to locate the child element 'response\\href'.");
            }

            XmlLiteElement objPropElement = objResponseElement.Elements.GetElement("propstat").Elements.GetElement("prop");

            if (objPropElement == null)
            {
                throw new Exception("Unable to locate the child element 'response\\propstat\\prop'.");
            }

            Path         = objHrefElement.Value;
            DisplayName  = objPropElement.Elements.GetElement("displayname").Value;
            Size         = Convert.ToInt64(objPropElement.Elements.GetElement("getcontentlength").Value);
            ModifiedDate = Convert.ToDateTime(objPropElement.Elements.GetElement("getlastmodified").Value);
        }
コード例 #4
0
        public void SerializeToStream(SerializedObject objSerializedObject, Stream objStream)
        {
            if (objSerializedObject == null)
            {
                throw new ArgumentNullException("objSerializedObject", "A valid non-null SerializedObject is required.");
            }
            if (objStream == null)
            {
                throw new ArgumentNullException("objStream", "A valid non-null Stream is required.");
            }

            XmlLiteElement objRootElement = new XmlLiteElement(objSerializedObject.Name);

            Serialize(objSerializedObject, objRootElement);

            XmlLiteDocument objDocument = new XmlLiteDocument(objRootElement);

            objDocument.ExportToStream(objStream);
        }
コード例 #5
0
        public void SerializeToFile(SerializedObject objSerializedObject, string strFilePath)
        {
            if (objSerializedObject == null)
            {
                throw new ArgumentNullException("objSerializedObject", "A valid non-null SerializedObject is required.");
            }

            XmlLiteElement objRootElement = new XmlLiteElement(objSerializedObject.Name);

            Serialize(objSerializedObject, objRootElement);

            if (File.Exists(strFilePath) == true)
            {
                File.Delete(strFilePath);
            }

            XmlLiteDocument objDocument = new XmlLiteDocument(objRootElement);

            objDocument.ExportToFile(strFilePath);
        }
コード例 #6
0
        public byte[] SerializeToByteArray(SerializedObject objSerializedObject)
        {
            if (objSerializedObject == null)
            {
                throw new ArgumentNullException("objSerializedObject", "A valid non-null SerializedObject is required.");
            }

            XmlLiteElement objRootElement = new XmlLiteElement(objSerializedObject.Name);

            Serialize(objSerializedObject, objRootElement);

            byte[]          bytData     = null;
            XmlLiteDocument objDocument = new XmlLiteDocument(objRootElement);

            using (MemoryStream objMemoryStream = new MemoryStream())
            {
                objDocument.ExportToStream(objMemoryStream);
                bytData = objMemoryStream.ToArray();
            }

            return(bytData);
        }