Connecting Tech Pros Worldwide Help | Site Map

Using Methods in Dictionary?

Member
 
Join Date: Aug 2008
Posts: 40
#1: 4 Weeks Ago
I have an enum with lots of elements in it. Now I need to invoke correspondent method for each enum (myEnum) element.
I created a Dictionary (myDictionary) with myEnum as key and Action as value.
But there is a problem that I am facing now, that is, there are some methods which needs some input parameters and some dont but all returns string. And here, Action supports delegate for no input parameter or upto four parameters. Is there any generic way to accomodate all of my methods in my myDictionary so that I could simply give myDictionary a key and it will invoke the correspondent method?

Here is what I have done up till now:


Dictionary<Message, Action> MessageAction = new Dictionary<Message, Action>()
{
{ myEnum.element1, method1 }
{ myEnum.element2, method2 }
};


public void method1()
{
// Logic for myEnum element 1
}
public void method2()
{
// Logic for myEnum element 2
}
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 7,148
#2: 4 Weeks Ago

re: Using Methods in Dictionary?


I don't know how you plan to use Action, since it doesn't return any value(you said you need a string)
Reply