I'm trying to generalize a C# class which holds multiple properties of the same type (and all of them have the same implementation as well).
What I want eventually is to remove all properties and hold a single Dictionary<string, type>
which maps each property using a unique ID.
Removing the properties will be too much of an effort at the moment, but some of the existing functions can be refactored so that instead of multiple 'copy-paste` to read/update a property, use a loop over the future dictionary and update per key.
How can I do the following?
//Simplified example
class Person {
public double Height { get; set; }
public double Weight { get; set; }
public double Age { get; set; }
public double SomethingElse { get; set; }
//.. maybe more
public void CopyPasteCode()
{
Height = -1.0;
Weight = -1.0;
Age = -1.0;
SomethingElse = -1.0;
}
public void Refactored()
{
var properties = //How to do this?
new List<ref double>()
{
ref Height, ref Weight, ref Age, ref IQ
};
foreach(var p in properties)
{
p = -1.0;
}
}
}