P
Peter
Hi
I have a property (item.Id) which contains a Guid. Based on the value
of this Guid I have to execute one of several different tasks. The
tasks are really all variations on the theme "obtain user data from a
database", and at the moment these "tasks" are just methods I call in
my class.
What is a nice syntax for this type of requirement? At the moment I
just use a big if-else (like that below), calling the appropriate
method, but I can't help but believe there's some more elegant
structure for this.
IList<User> userList;
if (item.Id == guid_1)
{
userList = FindUsers_1();
}
else if (item.Id == guid_2)
{
userList = FindUsers_2();
}
else if (item.Id = guid_3)
{
userList = FindUsers_3();
}
else
{
userList = FindUsers_X();
}
Thanks,
Peter
I have a property (item.Id) which contains a Guid. Based on the value
of this Guid I have to execute one of several different tasks. The
tasks are really all variations on the theme "obtain user data from a
database", and at the moment these "tasks" are just methods I call in
my class.
What is a nice syntax for this type of requirement? At the moment I
just use a big if-else (like that below), calling the appropriate
method, but I can't help but believe there's some more elegant
structure for this.
IList<User> userList;
if (item.Id == guid_1)
{
userList = FindUsers_1();
}
else if (item.Id == guid_2)
{
userList = FindUsers_2();
}
else if (item.Id = guid_3)
{
userList = FindUsers_3();
}
else
{
userList = FindUsers_X();
}
Thanks,
Peter