📜  堆栈溢出 - SQL 代码示例

📅  最后修改于: 2022-03-11 15:04:52.194000             🧑  作者: Mango

代码示例10
void Main()
{
    var s = new StringBuilder();
    s.Append("Id,Name\r\n");
    s.Append("1,one\r\n");
    var config = new CsvConfiguration(CultureInfo.InvariantCulture)
    {
    };
    using (var reader = new StringReader(s.ToString()))
    using (var csv = new CsvReader(reader, config))
    {
        csv.Context.RegisterClassMap();
        csv.GetRecords().ToList().Dump();
    }
}

private class Foo
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string RawRow { get; set; }
}

private class FooMap : ClassMap
{
    public FooMap()
    {
        Map(m => m.Id);
        Map(m => m.Name);
        Map(m => m.RawRow).Convert(args => args.Row.Parser.RawRecord);
    }
}