本文整理汇总了C#中CsvReader.ReadFrom方法的典型用法代码示例。如果您正苦于以下问题:C# CsvReader.ReadFrom方法的具体用法?C# CsvReader.ReadFrom怎么用?C# CsvReader.ReadFrom使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CsvReader
的用法示例。
在下文中一共展示了CsvReader.ReadFrom方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Given_an_unsorted_file__should_return_a_sorted_file
public void Given_an_unsorted_file__should_return_a_sorted_file()
{
var headings = new[] { "Number", "Name" };
var records = new List<Record>
{
new Record(new[] { "2", "Two" }, headings),
new Record(new[] { "4", "Four" }, headings),
new Record(new[] { "6", "Six" }, headings),
new Record(new[] { "8", "Eight" }, headings),
new Record(new[] { "9", "Nine" }, headings),
new Record(new[] { "7", "Seven" }, headings),
new Record(new[] { "5", "Five" }, headings),
new Record(new[] { "3", "Three" }, headings),
new Record(new[] { "1", "One" }, headings)
};
var reader = new CsvReader(new DelimitedDataReader(new StreamTokenizer()));
var writer = new CsvWriter();
var comparer = new RecordKeyComparer(new StringFieldComparer("Number"));
writer.WriteTo("UnsortedNumbers.csv", records, true);
var sorted = reader
.ReadFrom(File.OpenRead("UnsortedNumbers.csv"), "\r\n", true)
.Sort(comparer);
writer.WriteTo("SortedNumbers.csv", sorted, true);
var actual = reader.ReadFrom(File.OpenRead("SortedNumbers.csv"), "\r\n", true);
var lastNumber = "";
Console.WriteLine("Number, Name");
foreach (var record in actual)
{
Console.WriteLine("{0}, {1}", record["Number"], record["Name"]);
record["Number"].ShouldBeGreaterThan(lastNumber);
lastNumber = record["Number"];
}
}