/// <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> LoadAsync <T>( string fileName, StorageFolder folder = null) { var json = await StringIOExtensions.LoadAsync(fileName, folder); return(Parse <T>(json)); }
/// <summary> /// Loads object graph from XML file serialized using DataContractSerializer. /// </summary> /// <typeparam name="T">The 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> LoadDataContractAsync <T>( string fileName, StorageFolder folder = null) { var xmlString = await StringIOExtensions.LoadAsync(fileName, folder); var ms = new MemoryStream(Encoding.UTF8.GetBytes(xmlString)); var ser = new DataContractSerializer(typeof(T)); T result = (T)ser.ReadObject(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".SaveAsync("abc.txt", KnownFolders.DocumentsLibrary); await "DEF".SaveAsync("abc.txt", KnownFolders.DocumentsLibrary); await "ABC2".SaveAsync("abc2.txt", KnownFolders.DocumentsLibrary); await new MessageDialog("Test files written", "WinRTXamlToolkit.Sample").ShowAsync(); var abc = await StringIOExtensions.LoadAsync("abc.txt", KnownFolders.DocumentsLibrary); await new MessageDialog(abc, "Test file read").ShowAsync(); }