Beispiel #1
0
        /// <summary>
        /// Reads out the next row out of the current CSV stream and calls for every detected
        /// field value the given action.
        /// </summary>
        /// <param name="valueAction">Action with one string parameter.</param>
        /// <returns>A task that represents the asynchronous operation. The value of the TResult
        /// parameter contains the number of parsed values.</returns>
        /// <returns>
        public async Task <int> ReadLineAsync(Action <int, string> valueAction)
        {
            if (valueAction == null)
            {
                throw new ArgumentNullException(nameof(valueAction));
            }

            var valueCount = 0;

            do
            {
                if (await _csvParser.NextTokenAsync(() => NextCharAsync()))
                {
                    valueAction(valueCount, _csvParser.Token.ToString());
                    valueCount++;
                }
            }while (_csvParser.State != CsvParser.TokenizerState.IsEndOfLine);

            _lineCount++;

            return(valueCount);
        }