FileHelpers optional columns

旧巷老猫 提交于 2019-12-12 01:57:47

问题


I have static numbers of columns which my program will fill by data let's say 3. However at the end there could be additionally diffrent number of columns for pictures paths. At the moment i cannot say how many there will be as information will be comming from db so will be diffrent numbers of them. Question is how should i prepapre my class for that purpose? As you see below i declare 3 static columns but i have troubles how to do it for unknown number of pictures columns. Should i add 100 of them and mark as Optional or there is other way?

 <FieldOrder(1)>
    <FieldQuoted(QuoteMode.AlwaysQuoted)>
    Public KategorieLevel3_5 As String

    <FieldOrder(2)>
    <FieldQuoted(QuoteMode.AlwaysQuoted)>
    Public KategorieLevel4_5 As String

    <FieldOrder(3)>
    <FieldQuoted(QuoteMode.AlwaysQuoted)>
    Public KategorieLevel5_5 As String

    <FieldOptional>
    <FieldOrder(4)>
    Public Pic_1 As String

...
    <FieldOptional>
    <FieldOrder(100)>
    Public Pic_100 As String

回答1:


You can add an array field.

<FieldOrder(4)>
Public Pic_1 As String()

If there could be zero pics, then you can also mark the property as optional.

<FieldOptional>
<FieldOrder(4)>
Public Pic_1 As String()

You can even set the minimum/maximum number of values in the array:

<FieldOrder(4)>
<FieldArrayLength(2, 8)>
Public Pic_1 As String()


来源:https://stackoverflow.com/questions/39526558/filehelpers-optional-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!