Exemplo n.º 1
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);
         }
     }
 }
Exemplo n.º 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       = false;
     FastIndexOfAny = true;
 }
Exemplo n.º 3
0
        public CsvFileReader(CsvSource csvSource, CsvDefinition csvDefinition)
        {
            var streamReader = csvSource.TextReader as StreamReader;

            if (streamReader != null)
            {
                BaseStream = streamReader.BaseStream;
            }
            if (csvDefinition == null)
            {
                csvDefinition = DefaultCsvDefinition;
            }
            fieldSeparator = csvDefinition.FieldSeparator;
            textQualifier  = csvDefinition.TextQualifier;

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

            ReadHeader(csvDefinition.Header);
        }