JimmyJimm JimmyJimm - 2 months ago 30
Vb.net Question

FileHelpers optional columns

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

Answer

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