Exemplo n.º 1
0
        /// <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="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 Task <T> ConvertFileAsync <T>(this IReader <T> 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.ConvertFileAsync(stream));
            }
        }