加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – CsvReaderException未处理

发布时间:2020-12-15 17:37:25 所属栏目:百科 来源:网络整理
导读:我不断遇到这个错误: 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 docum
我不断遇到这个错误:

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();
}

和我的班:

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

我失踪了什么

解决方法

文档说明它将映射到“属性”.你的班有Fields.进行此更改:
public class FormattedRow
{
    public string IDOrderAlpha { get; set; }
    // add { get; set; } for all
}

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读