gpt4 book ai didi

c# - Csv 阅读器异常未处理

转载 作者:可可西里 更新时间:2023-11-01 09:04:09 24 4
gpt4 key购买 nike

我一直遇到这个错误:

An unhandled exception of type 'CsvHelper.CsvReaderException' occurred in CsvHelper.dll

Additional information: No properties are mapped for type 'RPS_String_Parse.Program+FormattedRow'.

但我相信我正在关注 the documentation正确。在引用了“入门”部分后,我实现了这个:

using (var sr = new StreamReader(filePath))
{
var csv = new CsvReader(sr);
var records = csv.GetRecords<FormattedRow>();
foreach (var record in records)
{
Console.WriteLine(record.Address1);
}

Console.ReadLine();
}

和我的类(class):

public class FormattedRow
{
public string IDOrderAlpha;
public string IDOrder;
public string AddressCompany;
public string Address1;
public string Address2;
public string AddressCity;
public string AddressState;
public string AddressZip;
public string AddressCountry;
public string ShipMethod;
public string ContactEmail;
public string ContactName;
public string ServiceRep;
public string CustomerPuchaseOrder;
}

我觉得这应该可行,因为文档指出:

Auto Mapping

If you don't supply a mapping file, auto mapping will be used. Auto mapping will map the properties in your class in the order they appear in. If the property is a custom class, it recursively maps the properties from that class in the order they appear in. If the auto mapper hits a circular reference, it will stop going down that reference branch

我错过了什么?

最佳答案

文档指出它将映射到 Properties。您的类(class)有 Fields。进行此更改:

public class FormattedRow
{
public string IDOrderAlpha { get; set; }
// add { get; set; } for all
}

这会将您的字段更改为“自动属性”。

关于c# - Csv 阅读器异常未处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23395319/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com