I have a class called SomethingProvider that contains:
private static string convertMapA(string convertA)
{
switch (convertA?.ToUpper())
{
case "NONE":
case "TEST":
case "MEHTEST":
return "None";
case "MEH":
return "meh";
case "DAY":
case "SOMEDAY":
return "da";
case "CON":
case "C":
return "cd";
default:
return convertA;
}
}
private static string convertMapB(string convertB)
{
switch (convertB?.ToUpper())
{
case "ANNY":
case "ANYU":
case "BLAH":
return "something";
default:
return convertB;
}
}
There can be multiple versions of this class, I.e ClassAlphaProvider, ClassBetaProvider. Each method Convert will have slightly different mappings dependent on its class.
And to make it more interesting there are multiple Projects, with multiple classes, with these convertMapping methods that alter per class.
Now, I was considering, dictionary mapping instead or, implement strategy pattern but feels overkill for strings mapping? Maybe even Db implementation of sorts?
What would be a good approach to refactoring this?
NOTE: the case statements change frequently. trying to consider open/close with the idea that the case statements change a lot.
convertA?.ToUpper() [...] case "SuperTEst"
Hmmmm....convertMapX
methods, than that might not be worth refactoring, but something tells me that's not the case. So, what else is affected? Do the signatures of these methods change? Do you have to add new methods? Do you have to change the calling code. Does some code rely on the string values returned, and if so, how?