I am writing a method in C# (SharePoint Services) which is supposed to return a SharePoint list name based on three conditions (Client, Country, and Location). There are multiple clients, countries and location, and the number is going to increase in the future.
Th method I wrote uses a series of "if" statements, nested into each other. It works fine, but I would like to think about maintainability of the method in future, and would really like to refactor it to something cleaner.
Can you give advice on any design patterns which would improve the code?
Here is the code:
if(client = "Client1")
{
if(country = "Country1"
{
if(location = "Location1"
{
return ListMatchingTheCriteria;
}
if(location = "Location2"
{
return ListMatchingTheCriteria;
}
...
}
if(country = "Country2"
{
if(location = "Location1"
{
return ListMatchingTheCriteria;
}
if(location = "Location2"
{
return ListMatchingTheCriteria;
}
...
}
}
if(client = "Client2")
{
if(country = "Country1"
{
if(location = "Location1"
{
return ListMatchingTheCriteria;
}
if(location = "Location2"
{
return ListMatchingTheCriteria;
}
...
}
if(country = "Country2"
{
if(location = "Location1"
{
return ListMatchingTheCriteria;
}
if(location = "Location2"
{
return ListMatchingTheCriteria;
}
...
}
}
...
Dictionary<(string client, string country, string location), IList<Whatever>>