In C# I have a struct with many fields, e.g. one called "key". I'm reading an .ini settings file, which has values for all the struct fields. Is there a way to use the field names as strings (like the myField string array below) to address the struct fields during the reading process (see below)? This would allow me to iterate the reading of many fields in a loop based on a string array.
private struct Foo {
public string key;
...
}
private Foo FooInstance;
string inStr;
string[] myFields[] = new string[10]{ ("key", "nextKey", ... );
for (int i=0;i<myFields.Length;i++) {
GetPrivateProfileString(section,myFields[i],"",inStr,255,file);
[convert myField[i] to the relevant Foo.key field] = inStr;
}