Ejemplo n.º 1
0
        private static string GetElementValue(CsvSourceLine line, int index)
        {
            if (index >= line.Elements.Length)
            {
                return(string.Empty);
            }

            return(line.Elements[index]);
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 /// <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;
 }