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; }
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); }
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); } } }