I have defined a generic class where T can be a specific interface or a collection of the interface.
public class BaseResponse<T> where T : IBaseResource, ICollection<T>, new()
However, when I try to create BaseResponse using IBaseResource I get the following error.
'System.Collections.Generic.List' cannot be used as type parameter 'T' in the generic type or method 'BaseResponse'. There is no implicit reference conversion from 'System.Collections.Generic.List<.Resources.IBaseResource >' to 'Vehicle.Api.Resources.IBaseResource'.
I even tried with following as well.
public class BaseResponse<T> where T : IBaseResource, ICollection<IBaseResource>, new()
Is the way I am defining multiple constraints is wrong or can't I use the ICollection of the same interface when defining multiple constraints? If it is achievable how can I achieve this?
edit -
To further clarify what I am expecting to achieve,
I am implementing a rest API where the response will be given by BaseResponse. For example, GET with single method will include BaseResponse<Entity> and GET will include BaseResponse<List<Entity>>