Ich setze derzeit alle Werte meines Klassenobjekts Record
.
Dies ist der Code, mit dem ich den Datensatz im Moment Eigenschaft für Eigenschaft auffülle.
// Loop through each field in the result set
for (int i = 0; i <= resultItems.Length; i++)
{
Record newRecord = new Record()
{
itemtype = resultItems[i - (fieldCount - 0)],
itemdesc = resultItems[i - (fieldCount - 1)],
prodcode = resultItems[i - (fieldCount - 2)],
proddesc = resultItems[i - (fieldCount - 3)],
curstat = resultItems[i - (fieldCount -4)],
totfree = resultItems[i - (fieldCount -5)],
totphys = resultItems[i - (fieldCount -6)],
pcolgroup = resultItems[i - (fieldCount -7)],
scolgroup = resultItems[i - (fieldCount -8)],
totpo = resultItems[i - (fieldCount - 9)],
totso = resultItems[i - (fieldCount - 10)],
quality = resultItems[i - (fieldCount - 11)],
statusdesc = resultItems[i - (fieldCount - 12)],
groupcode = resultItems[i - (fieldCount - 13)],
qualitydes = resultItems[i - (fieldCount - 14)],
pcoldesc = resultItems[i - (fieldCount - 15)],
scoldesc = resultItems[i - (fieldCount - 16)],
pgroupdesc = resultItems[i - (fieldCount - 17)],
};
}
Kann ich jede Eigenschaft dynamisch durchlaufen, ohne alle Eigenschaftsnamen fest zu codieren?
So etwas in der Art:
// Create new Record instance
Record newRecord = new Record();
for (int e = 0; e < propertyCount.Length - 1; e++)
{
newRecord[fieldname] = resultItems[i - (fieldCount - e)];
}