CsvLine CreateLine() { var fields = _fields; bool isEmpty = fields.Count == 0 || (fields.Count == 1 && string.IsNullOrEmpty(fields[0])); if (!FieldCount.HasValue && (!isEmpty || !_behaviour.SkipEmptyLines)) { FieldCount = fields.Count; } var count = fields.Count(); if (!isEmpty && count < FieldCount) { if (_behaviour.MissingFieldAction == MissingFieldAction.ParseError) { throw new MissingFieldCsvException(_rawData.ToString(), _location, fields.Count); } } if (count < FieldCount) { string s = _behaviour.MissingFieldAction == MissingFieldAction.ReplaceByNull ? null : ""; while (fields.Count < FieldCount) { fields.Add(s); } } var line = new CsvLine(fields, isEmpty); return(line); }
public CsvDataReader(TextReader reader, CsvLayout csvLayout, CsvBehaviour csvBehaviour, IConverter converter) { _parser = new CsvParser(reader, csvLayout, csvBehaviour); _header = _parser.Header; _line = null; _converter = converter; _enumerator = _parser.GetEnumerator(); }
public CsvDataReader(TextReader reader, CsvLayout csvLayout, CsvBehaviour csvBehaviour, CultureInfo cultureInfo) { _parser = new CsvParser(reader, csvLayout, csvBehaviour); _header = _parser.Header; _line = null; _converter = new Converter(cultureInfo ?? CultureInfo.InvariantCulture); _enumerator = _parser.GetEnumerator(); _schema = csvLayout.Schema; }
public bool Read() { if (_eof || !_enumerator.MoveNext()) { _eof = true; return(false); } _line = _enumerator.Current; return(true); }
public ProcessingResult(Func <CsvLineBuilder, CsvBehaviour, ProcessingResult> Next, CsvLineBuilder state, CsvLine line = null) : this(new Option <CsvLine>(line), Next, state) { }