本文整理汇总了C#中Mapper.Extract方法的典型用法代码示例。如果您正苦于以下问题:C# Mapper.Extract方法的具体用法?C# Mapper.Extract怎么用?C# Mapper.Extract使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mapper
的用法示例。
在下文中一共展示了Mapper.Extract方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldCreateCustomerFromCsv
public void ShouldCreateCustomerFromCsv()
{
Schema schema = new Schema().AddColumn<string>("name").AddColumn<DateTime>("modified").AddColumn<int>("visits");
Mapper<Customer> mapper = new Mapper<Customer>().Map(c => c.Name).To("name").Map(c => c.LastModified).To("modified").Map(c => c.Visits).To("visits");
const string data = @"name,modified,visits
bob,12/31/2012,108";
Stream stream = new MemoryStream(Encoding.Default.GetBytes(data));
SeparatedValueParserOptions options = new SeparatedValueParserOptions() { IsFirstRecordSchema = true };
SeparatedValueParser parser = new SeparatedValueParser(stream, schema, options);
FlatFileReader reader = new FlatFileReader(parser);
IEnumerable<Customer> customers = mapper.Extract(reader);
Assert.AreEqual(1, customers.Count(), "The wrong number of records were mapped.");
Assert.AreEqual("bob", customers.First().Name, "The customer name was not parsed correctly.");
Assert.AreEqual(new DateTime(2012, 12, 31), customers.First().LastModified, "The customer modified date was not parsed correctly.");
Assert.AreEqual(108, customers.First().Visits, "The customer visits was not parsed correctly.");
}