예제 #1
0
        /// <summary>
        /// Creates a new CSV writer using the given <see cref="ICsvSerializer"/>.
        /// </summary>
        /// <param name="serializer">The serializer.</param>
        /// <param name="leaveOpen">true to leave the reader open after the CsvReader object is disposed, otherwise false.</param>
        public CsvWriter(ICsvSerializer serializer, bool leaveOpen)
        {
            if (serializer == null)
            {
                throw new ArgumentNullException(nameof(serializer));
            }

            if (serializer.Configuration == null)
            {
                throw new CsvConfigurationException("The given serializer has no configuration.");
            }

            if (!(serializer.Configuration is ICsvWriterConfiguration))
            {
                throw new CsvConfigurationException("The given serializer does not have a configuration that works with the writer.");
            }

            this.serializer = serializer;
            configuration   = (ICsvWriterConfiguration)serializer.Configuration;
            this.leaveOpen  = leaveOpen;
        }
예제 #2
0
 /// <summary>
 /// Creates a new CSV writer using the given <see cref="TextWriter"/>.
 /// </summary>
 /// <param name="writer">The <see cref="StreamWriter"/> use to write the CSV file.</param>
 /// <param name="configuration">The configuration.</param>
 public CsvWriter(TextWriter writer, ICsvWriterConfiguration configuration) : this(new CsvSerializer(writer, configuration), false)
 {
 }