In the code below, I want to access nth item of a list of class cPropertyValues, and return member variable that is represented by propertyName. I can do this by a simple string check on each member. But there are 50 members in cPropertyValues class. So is there a better way to access class members without performing individual comparison?
1 2 3 4 5 6 7
public string getPropertyValueByName(string propertyName)
{
List<cPropertyValues> list = GlobalClass.get_mPropertyValuesList;
return (list[GlobalClass.itemIndex]).propertyName; //this won't work, since propertyName is not a member of cPropertyValues.
}