Mapping to a Dictionary

后端 未结 2 740
我在风中等你
我在风中等你 2021-01-20 11:30

I was trying to map a csv file so that each record would simply be a Dictionary.

I am receiving an

Argument

2条回答
  •  没有蜡笔的小新
    2021-01-20 11:52

    Unfortunately, there currently is no support for mapping to a Dictionary.

    If you try doing GetRecords>(), you will get an error.

    Types that inhererit IEnumerable cannot be auto mapped. Did you accidentally call GetRecord or WriteRecord which acts on a single record instead of calling GetRecords or WriteRecords which acts on a list of records?
    

    You can't map to a Dictionary either. In a mapping you need to specify a property of the class for the field to be mapped to. The indexer is not a member property which is why you're getting that error.

    SOLUTION:

    What you CAN do is this:

    var record = csv.GetRecord();
    

    You can use it as a dynamic object.

    DESIRED SOLUTION

    Internally, it uses the ExpandoObject, so you can do this.

    var dict = csv.GetRecord() as IDictionary;
    

提交回复
热议问题