first:
public static String ConvertServerToClientAdapter(String adapterServer)
{
string temp = adapterServer.Substring(0, adapterServer.IndexOf("/"));
switch (temp)
{
case "f":
{
return "FA";
}
case "g":
{
return "Gi";
}
case "s":
{
return "SE";
}
case "a":
{
return "ATM";
}
default:
return null;
}
}
second:
public static String ConvertClientToServerAdapter(String adapterClient)
{
switch (adapterClient)
{
case "FA":
{
return "f";
}
case "Gi":
{
return "g";
}
case "SE":
{
return "s";
}
case "ATM":
{
return "a";
}
default:
return null;
}
}
You can store the string pairs in a dictionary. That will reduce the duplication of having two places in the code saying that ‘a’ is paired with ‘ATM’.
For the forward conversion, just index the dictionary.
return _dict[adapterServer];.Edit: maybe it should be TryGetValue if you want to return null for invalid input, rather than throwing exceptions.
For backward, use linq:
You can swap what is forward/backward depending on what is used more often, forward dictionary indexing is faster than linq.