When returning the following function
public Guid GetUserFilterValue( string filterID )
As
Func<string, object>
I am getting the error that it has the wrong return type. If I change the return type to anything other than Guid it compiles. Any ideas?
This would usually work if the return type was a reference type, because Func<T, TResult> is covariant for T; but Guid is a value type, this is why your method is not a valid candidate for Func<string, object>.
From MSDN:
Variance applies only to reference types; if you specify a value type for a variant type parameter, that type parameter is invariant for the resulting constructed type.
As a workaround, you could use a lambda expression:
Func<string, object> f = filterId => GetUserFilterValue(filterId);
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