I have a message coming into my C# app which is an object serialized as JSON, when i de-serialize it I have a \"Name\" string
and a \"Payload\" string[]
It sounds like you probably want something like:
Dictionary> functions = ...;
This is assuming the function returns an int
(you haven't specified). So you'd call it like this:
int result = functions[name](parameters);
Or to validate the name:
Func function;
if (functions.TryGetValue(name, out function))
{
int result = function(parameters);
...
}
else
{
// No function with that name
}
It's not clear where you're trying to populate functions
from, but if it's methods in the same class, you could have something like:
Dictionary> functions =
new Dictionary>
{
{ "Foo", CountParameters },
{ "Bar", SomeOtherMethodName }
};
...
private static int CountParameters(string[] parameters)
{
return parameters.Length;
}
// etc