コード例 #1
0
        /// <summary>
        ///     Parses a Csv file using the supplied model.  File and Class must match exactly
        /// </summary>
        /// <typeparam name="TDataRow">model type for csv file row</typeparam>
        /// <param name="reader">text reader</param>
        /// <param name="cfg">parser configuration</param>
        /// <param name="logger">injected logger</param>
        /// <returns>data rows</returns>
        private static IEnumerable <TDataRow> ParseFle <TDataRow>(TextReader reader, ParserConfiguration cfg, ILogger logger)
            where TDataRow : new()
        {
            using var parser = new LumenWorksCsvParser <TDataRow>(cfg, logger);

            return(parser.ParseStream(reader));
        }
コード例 #2
0
        /// <summary>
        ///     Parses a Csv file using the supplied model.  File and Class must match exactly
        /// </summary>
        /// <typeparam name="TDataRow">model type for csv file row</typeparam>
        /// <param name="filePath">path to file</param>
        /// <param name="cfg">parser configuration</param>
        /// <param name="logger">injected logger</param>
        /// <returns>data rows</returns>
        private static IEnumerable <TDataRow> ParseFle <TDataRow>(string filePath, ParserConfiguration cfg, ILogger logger)
            where TDataRow : new()
        {
            using var parser = new LumenWorksCsvParser <TDataRow>(cfg, logger);

            var context = new ParserContext(new Uri(filePath));

            var result = parser.Retrieve(context);

            if (result.Metadata.Exception != null)
            {
                throw new InvalidOperationException("Parse Error", result.Metadata.Exception);
            }

            return(result.Data);
        }