I have the following generic class:
public class DomainValidator<TRequest> : IValidator<TRequest> where TRequest : IRequest, IRequest<object>
{
}
As you can see, I have 2 types specified for type of TRequest
: IRequest
with no type, and IRequest<object>
with a type of any.
If I use this DomainValidator
class anywhere, Visual Studio compiler always complains that the type is not convertable to type IRequest
, because it has it's own type parameter.
I have looked at other similar questions, but none of them have a type parameter, which has it's own type. Is it possible to do what I'm trying to achieve?
UPDATE
Here is how I am using this generic class and where it fails.
The following class RequestThatDoesntWorkValidator
does not work, because RequestThatDoesntWork
does not provide a type for IRequest
as it doesn't need to:
public class RequestThatDoesntWorkValidator : DomainValidator<RequestThatDoesntWork>
{
}
public class RequestThatDoesntWork : IRequest
{
}
But the following class RequestThatDoesWorkValidator
seems to work because RequestThatDoesWork
provides a type for IRequest
:
public class RequestThatDoesWorkValidator : DomainValidator<RequestThatDoesWork>
{
}
public class RequestThatDoesWork : IRequest<List<string>>
{
}
I hope this makes more sense.