예제 #1
0
        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);
        }
예제 #2
0
 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();
 }
예제 #3
0
 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;
 }
예제 #4
0
 public bool Read()
 {
     if (_eof || !_enumerator.MoveNext())
     {
         _eof = true;
         return(false);
     }
     _line = _enumerator.Current;
     return(true);
 }
예제 #5
0
 public ProcessingResult(Func <CsvLineBuilder, CsvBehaviour, ProcessingResult> Next, CsvLineBuilder state, CsvLine line = null)
     : this(new Option <CsvLine>(line), Next, state) { }