Exemple #1
0
        /// <summary>
        /// Reads a record from the CSV file.
        /// </summary>
        /// <returns>A <see cref="T:String[]" /> of fields for the record read.</returns>
        public virtual string[] Read()
        {
            try
            {
                if (configuration.HasExcelSeparator && !hasExcelSeparatorBeenRead)
                {
                    ReadExcelSeparator();
                }

                reader.ClearRawRecord();

                var row = ReadLine();

                if (configuration.DetectColumnCountChanges && row != null)
                {
                    if (columnCount > 0 && columnCount != row.Length)
                    {
                        throw new CsvBadDataException("An inconsistent number of columns has been detected.");
                    }

                    columnCount = row.Length;
                }

                return(row);
            }
            catch (Exception ex)
            {
                var csvHelperException = ex as CsvHelperException ?? new CsvParserException("An unexpected error occurred.", ex);
                ExceptionHelper.AddExceptionData(csvHelperException, Row, null, null, null, record.ToArray());

                throw csvHelperException;
            }
        }
Exemple #2
0
        /// <summary>
        /// Reads a record from the CSV file.
        /// </summary>
        /// <returns>A <see cref="T:String[]" /> of fields for the record read.</returns>
        public virtual string[] Read()
        {
            try
            {
                reader.ClearRawRecord();

                var row = ReadLine();

                return(row);
            }
            catch (Exception ex)
            {
                var csvHelperException = ex as CsvHelperException ?? new CsvParserException("An unexpected error occurred.", ex);
                ExceptionHelper.AddExceptionData(csvHelperException, Row, null, null, null, record.ToArray());

                throw csvHelperException;
            }
        }