当前位置: 首页>>代码示例>>C#>>正文


C# CsvWriter.WriteRecordAsync方法代码示例

本文整理汇总了C#中CsvWriter.WriteRecordAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CsvWriter.WriteRecordAsync方法的具体用法?C# CsvWriter.WriteRecordAsync怎么用?C# CsvWriter.WriteRecordAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CsvWriter的用法示例。


在下文中一共展示了CsvWriter.WriteRecordAsync方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: write_record_async_values_can_be_an_enumerable

        public async Task write_record_async_values_can_be_an_enumerable()
        {
            using (var stringWriter = new StringWriter())
            {
                using (var writer = new CsvWriter(stringWriter))
                {
                    await writer.WriteRecordAsync(new List<string>(new string[] { "one", null, "three", null, "five", null }));
                }

                Assert.Equal("one,,three,,five," + Environment.NewLine, stringWriter.ToString());
            }
        }
开发者ID:modulexcite,项目名称:KBCsv,代码行数:12,代码来源:CsvWriterFixture.cs

示例2: write_record_async_uses_value_delimiter_always_if_force_is_true

        public async Task write_record_async_uses_value_delimiter_always_if_force_is_true()
        {
            using (var stringWriter = new StringWriter())
            {
                using (var writer = new CsvWriter(stringWriter))
                {
                    writer.ValueDelimiter = '\'';
                    writer.ForceDelimit = true;
                    await writer.WriteRecordAsync("can", "can't", "will", "won't");
                }

                Assert.Equal("'can','can''t','will','won''t'" + Environment.NewLine, stringWriter.ToString());
            }
        }
开发者ID:modulexcite,项目名称:KBCsv,代码行数:14,代码来源:CsvWriterFixture.cs

示例3: write_record_async_uses_new_line

        public async Task write_record_async_uses_new_line()
        {
            using (var stringWriter = new StringWriter())
            {
                using (var writer = new CsvWriter(stringWriter))
                {
                    writer.NewLine = "<<NL>>";
                    await writer.WriteRecordAsync("one", "two", "three");
                    await writer.WriteRecordAsync("four", "five", "six");
                }

                Assert.Equal("one,two,three<<NL>>four,five,six<<NL>>", stringWriter.ToString());
            }
        }
开发者ID:modulexcite,项目名称:KBCsv,代码行数:14,代码来源:CsvWriterFixture.cs

示例4: write_record_async_uses_value_separator

        public async Task write_record_async_uses_value_separator()
        {
            using (var stringWriter = new StringWriter())
            {
                using (var writer = new CsvWriter(stringWriter))
                {
                    writer.ValueSeparator = ';';
                    await writer.WriteRecordAsync("one", "two", "three");
                }

                Assert.Equal("one;two;three" + Environment.NewLine, stringWriter.ToString());
            }
        }
开发者ID:modulexcite,项目名称:KBCsv,代码行数:13,代码来源:CsvWriterFixture.cs

示例5: write_record_async_uses_value_delimiter_where_necessary

        public async Task write_record_async_uses_value_delimiter_where_necessary()
        {
            using (var stringWriter = new StringWriter())
            {
                using (var writer = new CsvWriter(stringWriter))
                {
                    writer.ValueDelimiter = '\'';
                    await writer.WriteRecordAsync("can", "can't", "will", "won't", " white space\t");
                }

                Assert.Equal("can,'can''t',will,'won''t',' white space\t'" + Environment.NewLine, stringWriter.ToString());
            }
        }
开发者ID:modulexcite,项目名称:KBCsv,代码行数:13,代码来源:CsvWriterFixture.cs

示例6: write_record_async_values_null_values_are_encoded_as_empty_strings

        public async Task write_record_async_values_null_values_are_encoded_as_empty_strings()
        {
            using (var stringWriter = new StringWriter())
            {
                using (var writer = new CsvWriter(stringWriter))
                {
                    await writer.WriteRecordAsync("one", null, "three", null, "five", null);
                }

                Assert.Equal("one,,three,,five," + Environment.NewLine, stringWriter.ToString());
            }
        }
开发者ID:modulexcite,项目名称:KBCsv,代码行数:12,代码来源:CsvWriterFixture.cs

示例7: write_record_async_values_increments_the_record_number

 public async Task write_record_async_values_increments_the_record_number()
 {
     using (var writer = new CsvWriter(new MemoryStream()))
     {
         await writer.WriteRecordAsync("one", "two", "three");
         Assert.Equal(1, writer.RecordNumber);
     }
 }
开发者ID:modulexcite,项目名称:KBCsv,代码行数:8,代码来源:CsvWriterFixture.cs

示例8: write_record_async_values_throws_if_value_delimiter_is_null_and_value_contains_carriage_return

 public void write_record_async_values_throws_if_value_delimiter_is_null_and_value_contains_carriage_return()
 {
     using (var writer = new CsvWriter(new MemoryStream()))
     {
         writer.ValueDelimiter = null;
         var ex = Assert.Throws<AggregateException>(() => writer.WriteRecordAsync(new string[] { "a value\r\nwith a carriage return" }).Wait());
         Assert.Equal(1, ex.InnerExceptions.Count);
         Assert.IsType<InvalidOperationException>(ex.InnerExceptions[0]);
         Assert.Equal("A value requires delimiting in order to be valid CSV, but no value delimiter has been set. The value is: a value\r\nwith a carriage return", ex.InnerExceptions[0].Message);
     }
 }
开发者ID:modulexcite,项目名称:KBCsv,代码行数:11,代码来源:CsvWriterFixture.cs

示例9: write_record_async_values_writes_values_to_the_text_writer

        public async Task write_record_async_values_writes_values_to_the_text_writer()
        {
            using (var stringWriter = new StringWriter())
            {
                using (var writer = new CsvWriter(stringWriter))
                {
                    await writer.WriteRecordAsync("one", "two", "three");
                }

                Assert.Equal("one,two,three" + Environment.NewLine, stringWriter.ToString());
            }
        }
开发者ID:modulexcite,项目名称:KBCsv,代码行数:12,代码来源:CsvWriterFixture.cs

示例10: write_record_async_values_throws_if_values_is_null

 public async Task write_record_async_values_throws_if_values_is_null()
 {
     using (var writer = new CsvWriter(new MemoryStream()))
     {
         await Assert.ThrowsAsync<ArgumentNullException>(() => writer.WriteRecordAsync((string[])null));
     }
 }
开发者ID:modulexcite,项目名称:KBCsv,代码行数:7,代码来源:CsvWriterFixture.cs

示例11: write_record_async_values_throws_if_disposed

 public async Task write_record_async_values_throws_if_disposed()
 {
     var writer = new CsvWriter(new MemoryStream());
     writer.Dispose();
     await Assert.ThrowsAsync<ObjectDisposedException>(() => writer.WriteRecordAsync("one", "two", "three"));
 }
开发者ID:modulexcite,项目名称:KBCsv,代码行数:6,代码来源:CsvWriterFixture.cs

示例12: write_record_async_record_increments_the_record_number

 public async Task write_record_async_record_increments_the_record_number()
 {
     using (var writer = new CsvWriter(new MemoryStream()))
     {
         await writer.WriteRecordAsync(new HeaderRecord());
         Assert.Equal(1, writer.RecordNumber);
     }
 }
开发者ID:modulexcite,项目名称:KBCsv,代码行数:8,代码来源:CsvWriterFixture.cs

示例13: write_record_async_record_throws_if_disposed

 public async Task write_record_async_record_throws_if_disposed()
 {
     var writer = new CsvWriter(new MemoryStream());
     writer.Dispose();
     await Assert.ThrowsAsync<ObjectDisposedException>(() => writer.WriteRecordAsync(new HeaderRecord()));
 }
开发者ID:modulexcite,项目名称:KBCsv,代码行数:6,代码来源:CsvWriterFixture.cs

示例14: WriteCsvAsync

        /// <summary>
        /// Asynchronously writes all rows in <paramref name="this"/> to <paramref name="csvWriter"/>.
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="this">
        /// The <see cref="DataTable"/>.
        /// </param>
        /// <param name="csvWriter">
        /// The <see cref="CsvWriter"/>.
        /// </param>
        /// <param name="writeHeaderRecord">
        /// If <see langword="true"/>, a header record will also be written, which will be comprised of the column names defined for <paramref name="this"/>.
        /// </param>
        /// <param name="maximumRows">
        /// The maximum number of rows from <paramref name="this"/> that should be written to <paramref name="csvWriter"/>.
        /// </param>
        /// <param name="objectToStringConverter">
        /// Provides a means of converting values in the <see cref="DataRow"/>s to <see cref="String"/>s.
        /// </param>
        /// <returns>
        /// The actual number of rows from <paramref name="this"/> written to <paramref name="csvWriter"/>.
        /// </returns>
        public async static Task<int> WriteCsvAsync(this DataTable @this, CsvWriter csvWriter, bool writeHeaderRecord, int? maximumRows, Func<object, string> objectToStringConverter)
        {
            @this.AssertNotNull("@this");
            csvWriter.AssertNotNull("csvWriter");
            objectToStringConverter.AssertNotNull("objectToStringConverter");

            var num = 0;

            if (writeHeaderRecord)
            {
                var columnNames = new string[@this.Columns.Count];

                for (var i = 0; i < columnNames.Length; ++i)
                {
                    columnNames[i] = @this.Columns[i].ColumnName;
                }

                await csvWriter.WriteRecordAsync(columnNames).ConfigureAwait(false);
            }

            var maximum = maximumRows.GetValueOrDefault(int.MaxValue);
            var buffer = new DataRecord[16];
            var bufferOffset = 0;

            foreach (DataRow row in @this.Rows)
            {
                var record = new DataRecord();

                for (var i = 0; i < row.ItemArray.Length; ++i)
                {
                    record.Add(objectToStringConverter(row.ItemArray[i]));
                }

                buffer[bufferOffset++] = record;

                if (bufferOffset == buffer.Length)
                {
                    // buffer full
                    await csvWriter.WriteRecordsAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
                    bufferOffset = 0;
                }

                if (++num == maximum)
                {
                    break;
                }
            }

            // write any outstanding data in buffer
            await csvWriter.WriteRecordsAsync(buffer, 0, bufferOffset).ConfigureAwait(false);

            return num;
        }
开发者ID:GitOffice,项目名称:DataPie,代码行数:76,代码来源:DataExtensions_Async.cs


注:本文中的CsvWriter.WriteRecordAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。