[academic theory disclaimer] :-)
not that i've ever tried it, however, you could create a dictionary that was keyed on the id and contained an action delegate. this would save the need to use case statements or if's etc, etc.
let the madness begin:
class Program
{
// example methods
static void Method1(string message)
{
Console.WriteLine(message);
}
static void Method2(int id, string message)
{
Console.WriteLine(string.Format("id: {0} message: {1}", id, message));
}
static void Method3()
{
Console.WriteLine("submitted");
}
static void Main(string[] args)
{
int targetId = 2; // or passed in id etc
// add the actions with examples of params
// and non param methods
var actions =
new Dictionary<int, Action>
{
{1, () => Method1("incomplete")},
{2, () => Method2(targetId, "approved")},
{3, () => Method3()}
};
if (actions.ContainsKey(targetId))
{
actions[targetId].Invoke();
}
else
{
// no method defined for this action
// do something about it
Console.WriteLine("no action defined here yet");
}
Console.ReadKey();
}
}
obviously, the Methodn
'methods' would be your proper 'bespoke' methods in each case.
[edit] - here's a little SO link in support of such a theory:
C# switch statement limitations - why?