C# - Silverlight - Dynamically calling a method

Posted by cmaduro on Stack Overflow See other posts from Stack Overflow or by cmaduro
Published on 2010-05-21T23:36:40Z Indexed on 2010/05/21 23:40 UTC
Read the original article Hit count: 248

Filed under:
|
|

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.
}

© Stack Overflow or respective owner

Related posts about metaprogramming

Related posts about c#