GurdeepS
GurdeepS

Reputation: 67223

Question on dictionary of delegates

I am writing an if/else alternative using a table driven method.

I have the following code:

var map = new[] 
{
    new 
    {
        Predicate = new Func<Type, bool>(type => type.IsInterface),
        Selector = new Func<Type, Delegate>(str, sww.Invoke())
    }
};

In the selector, I want to return a delagate which I can invoke (points to another method), or specify in line (eg (delegate() { // Do something here. }).

I am using (and modifying) the code from here: Table Driven Method issue

How can I do this?

Upvotes: 0

Views: 431

Answers (1)

M.A. Hanin
M.A. Hanin

Reputation: 8074

Instead of Delegate, you can use a specific delegate type, such as Action:

Selector = new Func<Type, Action>(str, sww.Invoke)

Upvotes: 3

Related Questions