/// <summary> /// Loads an object graph from a JSON file. /// </summary> /// <typeparam name="T">The type of the expected object graph reference.</typeparam> /// <param name="fileName">Name of the file.</param> /// <param name="folder">The folder.</param> /// <returns></returns> public static async Task <T> LoadFromJsonFile <T>( string fileName, StorageFolder folder = null) { var json = await StringIOExtensions.ReadFromFile(fileName, folder); return(LoadFromJsonString <T>(json)); }
public static async Task <T> LoadFromJsonFile <T>( string fileName, StorageFolder folder = null) { var json = await StringIOExtensions.ReadFromFile(fileName, folder); var ms = new MemoryStream(UTF8Encoding.UTF8.GetBytes(json)); var ser = new DataContractJsonSerializer(typeof(T)); T result = (T)ser.ReadObject(ms); return(result); }
/// <summary> /// Loads an object graph from XML file serialized using XmlSerializer. /// </summary> /// <typeparam name="T">Type of the returned object graph reference.</typeparam> /// <param name="fileName">Name of the file.</param> /// <param name="folder">The folder.</param> /// <returns>Object graph reference.</returns> public static async Task <T> LoadFromXmlFile <T>( string fileName, StorageFolder folder = null) { var xmlString = await StringIOExtensions.ReadFromFile(fileName, folder); var ms = new MemoryStream(Encoding.UTF8.GetBytes(xmlString)); var ser = new XmlSerializer(typeof(T)); T result = (T)ser.Deserialize(ms); return(result); }
private static async void InputDialogAndStringIOTest() { var dialog = new InputDialog(); await dialog.ShowAsync("Title", "Text", "OK", "Cancel"); await new MessageDialog(dialog.InputText, "WinRTXamlToolkit.Sample").ShowAsync(); await "ABC".WriteToFile("abc.txt", KnownFolders.DocumentsLibrary); await "DEF".WriteToFile("abc.txt", KnownFolders.DocumentsLibrary); await "ABC2".WriteToFile("abc2.txt", KnownFolders.DocumentsLibrary); await new MessageDialog("Test files written", "WinRTXamlToolkit.Sample").ShowAsync(); var abc = await StringIOExtensions.ReadFromFile("abc.txt", KnownFolders.DocumentsLibrary); await new MessageDialog(abc, "Test file read").ShowAsync(); }