views:

81

answers:

1

Can someone help me sort out this compiler error?

I have a class like this

public class Test {
    public delegate void TestAction<T>(T arg);
    public delegate void TestActionCaller<T1, T2>(T1 arg, TestAction<T2> action);

    public static void Call<T1,T2>(TestActionCaller<T1,T2> actioncaller) {
        actioncaller(default(T1), arg => { });
    }
}

Then I have the following code

public class TestCaller {
    static TestCaller() {
        Test.Call<int, int>((arg,action)=>action(arg));
    }
}

This works fine.

But if I move the TestCaller to another assembly (exactly the same code as above) I get a compiler error "Delegate 'TestAction' does not take '1' arguments."

+2  A: 

I believe the compiler cannot infer parameters and you need to specify their type explicitly:

Test.Call((int arg, TestAction<int> action) => action(arg));
Darin Dimitrov
doh, why didn't I test that. It worked. Thanks
adrianm