I have a class with an overloaded method:
MyClass.DoThis(Action<Foo> action);
MyClass.DoThis(Action<Bar> action);
I want to pass a lambda expression to the Action version:
MyClass.DoThis( foo => foo.DoSomething() );
Unfortunately, Visual Studio rightly cannot tell the difference between the Action<Foo>
and Action<Bar>
versions, due to the type inference surrounding the "foo" variable -- and so it raises a compiler error:
The call is ambiguous between the following methods or properties: 'MyClass.DoThis(System.Action
<Foo>
)' and 'MyClass.DoThis(System.Action<Bar>
)'
What's the best way to get around this?