Is there anyway in C# to call a method based on a Enum and/or class?
Say if I were to call
Controller<Actions.OnEdit, Customer>(customer);
Could I do something like this then?
public void Controller<TAction, TParam>(TParam object)
{
Action<TParam> action = FindLocalMethodName(TAction);
action(object);
}
private Action<T> FindLocalMethodName(Enum method)
{
//Use reflection to find a metode with
//the name corresponding to method.ToString()
//which accepts a parameters type T.
}
This should do it. Assume
objis the object you want to call the method on…Note that the method has to be public or as accessible to the reflecting code as it would be without reflection because Silverlight has very limited reflection of non-public methods.