public void AddLine(CSVLine line)
        {
            if (line.FieldsCount != m_nbFields)
            {
                throw new ArgumentException(String.Format("line fields count {0} does not match with table fields count {1}", line.FieldsCount, m_nbFields));
            }

            m_Lines.Add(line);
        }
Пример #2
0
        public void AddLine(CSVLine line)
        {
#if DEBUG
            if (null == line)
            {
                throw new ArgumentNullException(nameof(line));
            }
#endif
            if (line.FieldsCount != m_nbFields)
            {
                throw new ArgumentException(string.Format("line fields count {0} does not match with table fields count {1}", line.FieldsCount, m_nbFields));
            }
            m_Lines.Add(line);
        }
Пример #3
0
        public _DATA_TYPE_ GetDataFor <_DATA_TYPE_, _T_>(Func <CSVLine, _DATA_TYPE_> fn, _T_ modelID)
        {
#if DEBUG
            if (null == fn)
            {
                throw new ArgumentNullException(nameof(fn));
            }
#endif
            CSVLine lineForModel = FindLineFor(modelID);
            try {
                return(fn(lineForModel));
            } catch (Exception ex) {
                throw new InvalidOperationException(string.Format("invalid data format for {0} {1}; exception : {2}", typeof(_T_).ToString(), modelID.ToString(), ex.ToString()));
            }
        }
        public CSVTable ParseToTable(string[] lines, int nbFields)
        {
            CSVTable table = new CSVTable(nbFields);

            List <string[]> parsedRawLines = Parse(lines);

            foreach (string[] l in parsedRawLines)
            {
                CSVLine newTableLine = new CSVLine(l.Length);
                for (int iField = 0; iField < newTableLine.FieldsCount; iField++)
                {
                    newTableLine[iField] = new CSVField(l[iField]);
                }

                table.AddLine(newTableLine);
            }

            return(table);
        }