/// <summary>
/// Reads the contents of the specified file using the specified character encoding and returns text.
/// </summary>
/// <param name="file">The file to read.</param>
/// <param name="encoding">The character encoding of the file.</param>
/// <returns>When this method completes successfully, it returns the contents of the file as a text string.</returns>
public static Task <string> ReadTextAsync(IStorageFile file, UnicodeEncoding encoding)
{
#if __ANDROID__ || __UNIFIED__ || WIN32 || TIZEN
return(PathIO.ReadTextAsync(file.Path, encoding));
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
return(Windows.Storage.FileIO.ReadTextAsync((Windows.Storage.StorageFile)((StorageFile)file), (Windows.Storage.Streams.UnicodeEncoding)((int)encoding)).AsTask());
#elif WINDOWS_PHONE
return(Task.Run <string>(async() =>
{
Stream s = await((StorageFile)file).OpenStreamForReadAsync();
using (StreamReader sr = new StreamReader(s, UnicodeEncodingHelper.EncodingFromUnicodeEncoding(encoding)))
return await sr.ReadToEndAsync();
}));
#else
throw new PlatformNotSupportedException();
#endif
}