I have taken over the redevelopment of an app which needs to come over from Xamarin Forms to .NET MAUI and while I move it over, I'm taking the opportinuity to fix and improve the code base. Makes sense to do it now that later.
In the code, I've seen a lot of these sort of chunks of code and want to improve them
if (openClains.Description.Contains("January"))
{
openClains.Description = openClains.Description.Replace("January", Translate.CheckBrand(Languages.Resource.January));
}
else if (openClains.Description.Contains("February"))
{
openClains.Description = openClains.Description.Replace("February", Translate.CheckBrand(Languages.Resource.Febuary));
}
else if (openClains.Description.Contains("March"))
{
openClains.Description = openClains.Description.Replace("March", Translate.CheckBrand(Languages.Resource.March));
} (and so on)
It doesn't look nice and seems overly complex when all it does is look for a month name (from returned from a webservice) and replace it with the month name in a different language.
I did consider writing an extension method, but the issue is the selection of the name from the resources file based on the name fed in plus it doesn't really remove the if/else
Is there a simpler way using (say) LINQ to do the replace rather than a pile of if/else or switch/case conditions?