I have a dictionary that contains an enum (key) and a method (value). All of the methods do something different; some of them use parameters and some of them don't. In order to store all methods in one dictionary, I've decided to use a struct as the sole parameter for each method. The parameters that the methods will use are all different (ie. some may need a range (int min, int max), or a string (string format)). What's the cleanest way to do this? Right now I have a couple parameters of each type to be used at will, and leave it up to the method caller and method to coordinate the correct usage. It's an ugly way to do things and usually if it's ugly there's a cleaner way. Looking for some input from folks who have done something similar!
Dictionary<Enums.MethodTypes, Func<MethodArguments, string>>
methodDictionary = new Dictionary<Enums.MethodTypes, Func<MethodArguments, string>
public struct MethodArguments
{
int intArg_1;
int intArg2_2;
string strArg_1;
string strArg_2;
double dblArg_1;
double dblArg_2;
public MethodArguments(int a1, int a2, string s1, string s2, double d1, double d2)
{
intArg_1 = a1;
intArg_2 = a2;
strArg_1 = s1;
strArg_2 = s2;
dblArg_1 = d1;
dblArg_2 = d2;
}
}
The big picture:
First and foremost, I just learned of the idea of a dictionary of functions and I'd love to use it, I think that's pretty cool. Based on user input that is linked to an enum, we execute the appropriate method. I would like to go this route (if it's possible) for reasons stated above, and to avoid a really large switch statement.