Looks like you just want to have a Dictionary<string, Action> that you can hook into lambda functions:
var actions = new Dictionary<string, Action>(); actions.Add("Foo", () => Console.WriteLine("Bar!")); Car myCar = new Car(); actions.Add("Vroom", () => myCar.Drive()); actions["Foo"](); //prints "Bar!" actions["Vroom"](); //invokes myCar.Drive
Thus, all the various signatures, or object references, or static methods or something else are processed by the lambda and its closure semantics.
If you want to pass any context or input to a set, you can provide an untyped context object that you can use when registering a method. Instead of having an Action without parameters, you would use an Action<object> instead:
var actions = new Dictionary<string, Action<object>>(); var JuanLuisSoldi = new Person(); actions.Add("Lunch Time", context => JuanLuisSoldi.Eat((Food)context)); Food lunch = new Apple(); actions["Lunch Time"](lunch);
Chris sinclair
source share