Reputation: 2122
I've been reading around and can't seem to find a way to allow a function to take a generic tuple at all but also haven't found anywhere that says a Tuple can't take generic parameters, is this at all possible in C#? Below is the type of function I want to define (obviously doesn't work).
public static TController CreateControllerWithAuthenticatedContextsAndResponseMessages<TController>(
List<Tuple<TRequest, TResponse, Func<TResponse>, Expression<Func<TRequest, bool>>>> genList,
string policyName)
where TController : class
where TRequest : class
where TResponse : class
{
}
Is this possible to do at all? Otherwise is there another way to take these parameters? The reason it's this complicated is because I want to make sure the user (us) can't pass the wrong number of each parameter as it needs one of each.
EDIT: sorry, should've been clearer. TRequest and TResponse need to be lists of generics because they'll be something like AddedThis, AddedThat. With result functions and expressions to match. This is for mocking a controller for testing.
Upvotes: 0
Views: 340
Reputation: 156918
Yes, it does work, but you have to define all the generic type parameters in the method's signature:
public static TController CreateControllerWithAuthenticatedContextsAndResponseMessages
<TController, TRequest, TResponse>
( ... )
Numbers 2 and 3 were missing.
Upvotes: 1