I have a class like this in a legacy system
public class MyObj
{
public string Pro1 { get; set; }
public string Pro2 { get; set; }
public string Pro3 { get; set; }
public string Pro4 { get; set; }
public string Pro5 { get; set; }
public string Pro6 { get; set; }
public string Pro7 { get; set; }
public string Pro8 { get; set; }
}
Unfortunately the Properties Pro1...Pro8 has been used everywhere in the application. To facilitate access, the developer opted to use reflection to loop through using property names.
typeof(MyObj).GetProperty($"Pro{index}");
This is really troublesome.
I would like to create a ordered list somehow to get rid of the reflection. Something like this
public List<string> PropertiesAsList()
{
Pro1,Pro2,Pro3,Pro4...
}
Which later I can do
PropertiesAsList[0] = "This should set to Pro1";
I can not alter or remove the propeties Pro1..Pro4 to list as they are required by other parts in the system. I am only trying a way to access them easily without reflection
I already know that I can create a function
SetPropertyByIndex(int index, string value)
{
//huge switch-case?
}
Is there a good/better way I can achieve what I want?