Beispiel #1
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);
        }
Beispiel #2
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);
        }