I have following C# code. It works fine; but the GetDestination() method is cluttered with multiple if conditions by using is operator.
In
This is a strongly typed, imperative language so if statements and type checking are going to happen.
Having said that, have you considered a virtual method on Role that can be overridden to provide a destination string?
A further alternative, a lookup table!
Dictionary<Type, string> paths = new Dictionary<TYpe, string>()
{
{ typeof(Manager), @"\ManagerHomeA" }
{ typeof(Accountant), @"\AccountantHomeC" }
{ typeof(Cleaner), "Cleaner" }
}
string path = @"\Home";
if(paths.ContainsKey(x.GetType())
path = paths[x];