Esempio n. 1
0
        /// <summary>
        /// Load an object from an XML file that is in the specified format.
        /// <newpara></newpara>
        /// <example>
        /// The following example loads serialized data (XML Document format) into a 'Test' class object,
        /// from the XML file 'Objects as XML.xml':
        /// <newpara></newpara>
        /// <code>
        /// Test test = new Test(); //Must use new to create the object - cannot set to null.
        /// ObjectXMLSerializer objectXMLSerializer = new ObjectXMLSerializer();
        /// test = (Test) objectXMLSerializer.Load(test, "Objects as XML.xml", SerializedFormatType.Document);
        /// </code>
        /// </example>
        /// </summary>
        /// <param name="ObjectToLoad">Object to be loaded.</param>
        /// <param name="XMLFilePathName">File Path name of the XML file containing object(s) serialized to XML.</param>
        /// <param name="SerializedFormat">XML serialized format to load the object from.</param>
        /// <returns>Returns an Object loaded from the XML file. If the Object could not be loaded returns null.</returns>
        public virtual Object Load(Object ObjectToLoad, string XMLFilePathName, SerializedFormatType SerializedFormat)
        {
            switch (SerializedFormat)
            {
            case SerializedFormatType.Binary:
                ObjectToLoad = this.LoadFromBinaryFormat(ObjectToLoad, XMLFilePathName, null);
                break;

            case SerializedFormatType.Document:
            default:
                ObjectToLoad = this.LoadFromDocumentFormat(ObjectToLoad, XMLFilePathName, null);
                break;
            }

            return(ObjectToLoad);
        }
Esempio n. 2
0
        /// <summary>
        /// Save an object to an XML file that is in the specified format.
        /// <newpara></newpara>
        /// <example>
        /// The following example saves a 'Test' class object (XML Document format) to the XML
        /// file 'Objects as XML.xml':
        /// <newpara></newpara>
        /// <code>
        /// Test objTest = new Test();  //Must use new to create the object - cannot set to null.
        /// ObjectXMLSerializer objObjectXMLSerializer = new ObjectXMLSerializer();
        /// bool success = objObjectXMLSerializer.Save(objTest, "Objects as XML.xml", SerializedFormatType.Document);
        /// </code>
        /// </example>
        /// </summary>
        /// <param name="ObjectToSave">Object to be saved.</param>
        /// <param name="XMLFilePathName">File Path name of the XML file to contain the object serialized to XML.</param>
        /// <param name="SerializedFormat">XML serialized format to load the object from.</param>
        /// <returns>Returns success of the object save.</returns>
        public virtual bool Save(Object ObjectToSave, string XMLFilePathName, SerializedFormatType SerializedFormat)
        {
            bool success = false;

            switch (SerializedFormat)
            {
            case SerializedFormatType.Binary:
                success = this.SaveToBinaryFormat(ObjectToSave, XMLFilePathName, null);
                break;

            case SerializedFormatType.Document:
            default:
                success = this.SaveToDocumentFormat(ObjectToSave, XMLFilePathName, null);
                break;
            }

            return(success);
        }