I am trying to retrieve a table with several columns and I have created a class that will be able to represent each row as an object with properties.
E.G.
class TableA {
int prop1;
int prop2;
....
}
I am using SqlDataReader to read the value for each row and then assigning it to the object that I have created
TableA tab = new TableA()
tab.prop1 = sqlreader.GetValue(prop1_ordinal).toString();
At the moment I need to explicitly state:
tab.prop1 = etc2..
tab.prop2 = etc2...
This can be quite troublesome when I have quite a few properties (20+ or so).
What other alternatives should I be using?
I am thinking of using a Dictionary or something of the sort but am not sure how to start. That way, I can just use a foreach loop to go through a list of all the properties and set the values.
Essentially, I don't want to put in too much redundant code just to set values.
After all the data has been put into the object, I will essentially write it to a CSV file after the values have been manipulated and changed.
Any thoughts will be appreciated?