Example #1
0
 /// <summary>
 /// Populates the current instance from a string
 /// </summary>
 /// <param name="hasHeaderRow">True if the file has a header row, otherwise false</param>
 /// <param name="csvContent">Csv text</param>
 /// <param name="encoding">Encoding</param>
 /// <param name="trimColumns">True if column values should be trimmed, otherwise false</param>
 public void Populate(bool hasHeaderRow, string csvContent, Encoding encoding, bool trimColumns)
 {
     using (ElencyCsvReader reader = new ElencyCsvReader(encoding, csvContent)
     {
         HasHeaderRow = hasHeaderRow, TrimColumns = trimColumns
     })
     {
         PopulateCsvFile(reader);
     }
 }
Example #2
0
 /// <summary>
 /// Populates the current instance from a stream
 /// </summary>
 /// <param name="stream">Stream</param>
 /// <param name="encoding">Encoding</param>
 /// <param name="hasHeaderRow">True if the file has a header row, otherwise false</param>
 /// <param name="trimColumns">True if column values should be trimmed, otherwise false</param>
 public void Populate(Stream stream, Encoding encoding, bool hasHeaderRow, bool trimColumns)
 {
     using (ElencyCsvReader reader = new ElencyCsvReader(stream, encoding)
     {
         HasHeaderRow = hasHeaderRow, TrimColumns = trimColumns
     })
     {
         PopulateCsvFile(reader);
     }
 }
Example #3
0
        /// <summary>
        /// Populates the current instance using the CsvReader object
        /// </summary>
        /// <param name="reader">CsvReader</param>
        private void PopulateCsvFile(ElencyCsvReader reader)
        {
            Headers.Clear();
            Records.Clear();

            bool addedHeader = false;

            while (reader.ReadNextRecord())
            {
                if (reader.HasHeaderRow && !addedHeader)
                {
                    reader.Fields.ForEach(field => Headers.Add(field));
                    addedHeader = true;
                    continue;
                }

                CsvRecord record = new CsvRecord();
                reader.Fields.ForEach(field => record.Fields.Add(field));
                Records.Add(record);
            }
        }