Exemplo n.º 1
0
 /// <summary>
 /// Converts a list of string values to a CSV text line
 /// </summary>
 /// <param name="csvLineWriter">The <see cref="CsvLineBuilder"/></param>
 /// <param name="values">List of string values</param>
 /// <returns>
 /// A CSV formated text line
 /// </returns>
 public static string Write(this CsvLineBuilder csvLineWriter, IEnumerable <string> values)
 {
     if (values == null)
     {
         throw new ArgumentNullException(nameof(values));
     }
     csvLineWriter.Clear();
     foreach (string value in values)
     {
         csvLineWriter.Append(value);
     }
     return(csvLineWriter.ToString());
 }
Exemplo n.º 2
0
        /// <summary>
        /// Reads all csv records out of the stream and gives back an enumerator of newly encoded csv strings.
        /// This method can be used as a line by line syntax checker.
        /// </summary>
        /// <param name="csvReader">The <see cref="CsvReader"/></param>
        /// <returns>
        /// An async enumerator of newly encoded csv strings
        /// </returns>
        public static async IAsyncEnumerable <string> ReadAllLinesAsync(this CsvReader csvReader)
        {
            var csvLineBuilder = new CsvLineBuilder()
            {
                Configuration = csvReader.Configuration
            };

            while (await csvReader.ReadLineAsync((i, s) => { csvLineBuilder.Append(s); }) > 0)
            {
                yield return(csvLineBuilder.ToString());

                csvLineBuilder.Clear();
            }
        }
        /// <summary>
        /// Parses a CSV text line and returns back again the complete line as CSV string.
        /// </summary>
        /// <param name="csvLineReader">The <see cref="CsvLineParser"/></param>
        /// <param name="line">A CSV formated text line</param>
        /// <returns>
        /// The complete row as CSV string if values are available; otherwise null.
        /// </returns>
        public static string Validate(this CsvLineParser csvLineReader, string line)
        {
            var csvLineBuilder = new CsvLineBuilder()
            {
                Configuration = csvLineReader.Configuration
            };

            return((csvLineReader.Read(line, (i, s) => { csvLineBuilder.Append(s); }) > 0) ? csvLineBuilder.ToString() : null);
        }