private static string GetElementValue(CsvSourceLine line, int index) { if (index >= line.Elements.Length) { return(string.Empty); } return(line.Elements[index]); }
private void ValidateTooManyColumns(CsvSourceLine line) { if (line.Count > this.headers.Count()) { var message = "The line (" + line.LineNumber + ") contains more elements (" + line.Count + ") than headers (" + this.headers.Count() + ") available."; line.ErrorMessages.Add(message); if (definition.ThrowExceptionOnError) { throw new InvalidOperationException(message); } } }
private CsvLine CreateDictionaryLine(CsvSourceLine line) { var indexedLine = new CsvLine(line); for (int index = 0; index < this.headers.Length; index++) { var header = this.headers.GetHeaderName(index); if (indexedLine.ContainsKey(header)) { line.ErrorMessages.Add($"A duplicate header name was found '{header}' on line {line.LineNumber}."); if (definition.ThrowExceptionOnError) { throw new DuplicateHeaderException(header.Name, line.LineNumber); } } indexedLine.Add(header, GetElementValue(line, index)); } return(indexedLine); }
/// <summary>Initializes a new instance of the <see cref="CsvLine" /> class.</summary> /// <param name="line">The line.</param> public CsvLine(CsvSourceLine line) { this.SourceLine = line; }