Example #1
0
        public CsvFileReader(CsvSource csvSource, CsvDefinition csvDefinition)
        {
            var streamReader = csvSource.TextReader as StreamReader;

            if (streamReader != null)
            {
                this.BaseStream = streamReader.BaseStream;
            }
            if (csvDefinition == null)
            {
                csvDefinition = DefaultCsvDefinition;
            }
            this._fieldSeparator = csvDefinition.FieldSeparator;
            this._textQualifier  = csvDefinition.TextQualifier;

            this._textReader = csvSource.TextReader;// new FileStream(csvSource.TextReader, FileMode.Open);


            this.ReadHeader(csvDefinition.Header);
        }
Example #2
0
        static CsvFile()
        {
            // Choosing default Field Separator is a hard decision

            // In theory the C of CSV means Comma separated

            // In Windows though many people will try to open the csv with Excel which is horrid with real CSV.

            // As the target for this library is Windows we go for Semi Colon.

            DefaultCsvDefinition = new CsvDefinition
            {
                EndOfLine      = "\r\n",
                FieldSeparator = ';',
                TextQualifier  = '"'
            };
            UseLambdas     = true;
            UseTasks       = true;
            FastIndexOfAny = true;
        }
Example #3
0
 public static void ToCsv <T>(this IEnumerable <T> source, CsvDestination csvDestination, CsvDefinition csvDefinition)
 {
     using (var csvFile = new CsvFile <T>(csvDestination, csvDefinition))
     {
         foreach (var record in source)
         {
             csvFile.Append(record);
         }
     }
 }