/// <summary> /// Transforms the given file into an object. /// This is done asynchronously. /// </summary> /// <typeparam name="T">The type of object to deserialise.</typeparam> /// <param name="reader">The reader object which converts the file.</param> /// <param name="stream">The file containing the object data.</param> /// <returns>An object containing all the retrieved data from the file.</returns> /// <exception cref="ArgumentNullException">If the given reader or stream /// does not exist.</exception> /// <exception cref="InvalidFormatException">If a file was provided /// which does not use one of the <see cref="SupportedFormats"/>-formats. /// </exception> public static Task <T> ConvertFileAsync <T>(this IReader <T> reader, StreamReader stream) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (stream == null) { throw new ArgumentNullException(nameof(stream)); } return(Task.Run(() => reader.ConvertFile(stream))); }
/// <summary> /// Transforms the given file into an object on the current thread. /// </summary> /// <param name="reader">The reader object which converts the file.</param> /// <param name="location">The file containing the object data.</param> /// <returns>An object containing all the retrieved data from the file.</returns> /// <exception cref="ArgumentNullException">If the given reader or stream /// does not exist.</exception> /// <exception cref="InvalidFormatException">If a file was provided /// which does not use one of the <see cref="SupportedFormats"/>-formats. /// </exception> public static object ConvertFile(this IReader reader, string location) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } if (string.IsNullOrEmpty(location)) { throw new ArgumentNullException(nameof(location)); } using (StreamReader stream = new StreamReader(location)) { return(reader.ConvertFile(stream)); } }