Exemple #1
0
        /// <summary>
        /// Saves an object to an XML file located in a specified isolated storage area, using a
        /// specified serialized format.
        /// </summary>
        ///
        /// <remarks>   Asim Naeem, 7/20/2017. </remarks>
        ///
        /// <param name="serializableObject">       Serializable object to be saved to file. </param>
        /// <param name="fileName">                 Name of the file in the isolated storage area to save
        ///                                         the object to. </param>
        /// <param name="isolatedStorageDirectory"> Isolated storage area directory containing the XML
        ///                                         file to save the object to. </param>
        /// <param name="serializedFormat">         XML serialized format used to save the object. </param>
        ///
        /// <example>
        /// <code>
        /// SerializableObject serializableObject = new SerializableObject();
        ///
        /// ObjectXMLSerializer&lt;SerializableObject&gt;.Save(serializableObject, "XMLObjects.xml", IsolatedStorageFile.GetUserStoreForAssembly(), SerializedFormat.Binary);
        /// </code>
        /// </example>


        public static void Save(T serializableObject, string fileName, IsolatedStorageFile isolatedStorageDirectory, ObjectXMLSerializer serializedFormat)
        {
            switch (serializedFormat)
            {
            case ObjectXMLSerializer.Binary:
                SaveToBinaryFormat(serializableObject, fileName, isolatedStorageDirectory);
                break;

            case ObjectXMLSerializer.Document:
            default:
                SaveToDocumentFormat(serializableObject, null, fileName, isolatedStorageDirectory);
                break;
            }
        }
Exemple #2
0
        /// <summary>
        /// Loads an object from an XML file located in a specified isolated storage area, using a
        /// specified serialized format.
        /// </summary>
        ///
        /// <remarks>   Asim Naeem, 7/20/2017. </remarks>
        ///
        /// <param name="fileName">                 Name of the file in the isolated storage area to load
        ///                                         the object from. </param>
        /// <param name="isolatedStorageDirectory"> Isolated storage area directory containing the XML
        ///                                         file to load the object from. </param>
        /// <param name="serializedFormat">         XML serialized format used to load the object. </param>
        ///
        /// <returns>
        /// Object loaded from an XML file located in a specified isolated storage area, using a
        /// specified serialized format.
        /// </returns>
        ///
        /// <example>
        /// <code>
        /// serializableObject = ObjectXMLSerializer&lt;SerializableObject&gt;.Load("XMLObjects.xml", IsolatedStorageFile.GetUserStoreForAssembly(), SerializedFormat.Binary);
        /// </code>
        /// </example>


        public static T Load(string fileName, IsolatedStorageFile isolatedStorageDirectory, ObjectXMLSerializer serializedFormat)
        {
            T serializableObject = null;

            switch (serializedFormat)
            {
            case ObjectXMLSerializer.Binary:
                serializableObject = LoadFromBinaryFormat(fileName, isolatedStorageDirectory);
                break;

            case ObjectXMLSerializer.Document:
            default:
                serializableObject = LoadFromDocumentFormat(null, fileName, isolatedStorageDirectory);
                break;
            }

            return(serializableObject);
        }