I've got legacy code that defined the following helper
public delegate R Function<T, R>(T t);
But I want to supply a Func<T,TResult>
casting attempts fail to compile
Cannot convert type '
System.Func<T,TResult>
' to 'Rhino.Mocks.Function<T,TResult>
'
Is there a way that not only compiles, but functions at runtime?
The problem is you are trying to combine two different delegate types: Func<T, TResult>
and Function<T, TResult>
. Even though they have the same signature they are different, and hence incompatible, types.
Use a lambda to create a conversion layer between the two.
Func<T, TResult> func = ...;
TheMethod(x => func(x));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With