/// <summary> /// Saves an object to an XML file using a specified serialized format. /// </summary> /// <example> /// <code> /// SerializableObject serializableObject = new SerializableObject(); /// /// ObjectXMLSerializer<SerializableObject>.Save(serializableObject, @"C:\XMLObjects.xml", SerializedFormats.Binary); /// </code> /// </example> /// <param name="serializableObject">Serializable object to be saved to file.</param> /// <param name="path">Path of the file to save the object to.</param> /// <param name="serializedFormat">XML serialized format used to save the object.</param> public static void Save(T serializableObject, string path, SerializedFormats serializedFormat) { switch (serializedFormat) { case SerializedFormats.Binary: SaveToBinaryFormat(serializableObject, path, null); break; case SerializedFormats.Document: default: SaveToDocumentFormat(serializableObject, null, path, null); break; } }
/// <summary> /// Saves an object to an XML file located in a specified isolated storage area, using a specified serialized format. /// </summary> /// <example> /// <code> /// SerializableObject serializableObject = new SerializableObject(); /// /// ObjectXMLSerializer<SerializableObject>.Save(serializableObject, "XMLObjects.xml", IsolatedStorageFile.GetUserStoreForAssembly(), SerializedFormats.Binary); /// </code> /// </example> /// <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> public static void Save(T serializableObject, string fileName, IsolatedStorageFile isolatedStorageDirectory, SerializedFormats serializedFormat) { switch (serializedFormat) { case SerializedFormats.Binary: SaveToBinaryFormat(serializableObject, fileName, isolatedStorageDirectory); break; case SerializedFormats.Document: default: SaveToDocumentFormat(serializableObject, null, fileName, isolatedStorageDirectory); break; } }
/// <summary> /// Loads an object from an XML file using a specified serialized format. /// </summary> /// <example> /// <code> /// // Always create a new object prior to passing to ObjectXMLSerializer.Load method. /// SerializableObject serializableObject = new SerializableObject(); /// /// serializableObject = ObjectXMLSerializer<SerializableObject>.Load(serializableObject, @"C:\XMLObjects.xml", SerializedFormats.Binary); /// </code> /// </example> /// <param name="serializableObject">Serializable object to be loaded from file.</param> /// <param name="path">Path of the 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 using the specified serialized format.</returns> public static T Load(string path, SerializedFormats serializedFormat) { T serializableObject = default(T); switch (serializedFormat) { case SerializedFormats.Binary: serializableObject = LoadFromBinaryFormat(path, null); break; case SerializedFormats.Document: default: serializableObject = LoadFromDocumentFormat(null, path, null); break; } return(serializableObject); }
/// <summary> /// Loads an object from an XML file located in a specified isolated storage area, using a specified serialized format. /// </summary> /// <example> /// <code> /// // Always create a new object prior to passing to ObjectXMLSerializer.Load method. /// SerializableObject serializableObject = new SerializableObject(); /// /// serializableObject = ObjectXMLSerializer<SerializableObject>.Load(serializableObject, "XMLObjects.xml", IsolatedStorageFile.GetUserStoreForAssembly(), SerializedFormats.Binary); /// </code> /// </example> /// <param name="serializableObject">Serializable object to be loaded from file.</param> /// <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> public static T Load(string fileName, IsolatedStorageFile isolatedStorageDirectory, SerializedFormats serializedFormat) { T serializableObject = default(T); switch (serializedFormat) { case SerializedFormats.Binary: serializableObject = LoadFromBinaryFormat(fileName, isolatedStorageDirectory); break; case SerializedFormats.Document: default: serializableObject = LoadFromDocumentFormat(null, fileName, isolatedStorageDirectory); break; } return(serializableObject); }