Any ideas how I can fix the following error or refactor my approach to avoid it?
I have the following interfaces defined:
public interface IApiClient<TConfig, TOrder>
where TConfig : IApiClientConfiguration
where TOrder : IApiClientOrder
{
TConfig Configuration { get; }
IApiClientOrderConverter<TOrder> GetOrderConverter();
Task<IEnumerable<TOrder>> GetNewOrdersAsync();
}
public interface IApiClientOrderConverter<TOrder>
where TOrder : IApiClientOrder
{
WarehouseOrder ClientOrderToWarehouseOrder(TOrder order);
}
With an implementation based on it:
public class SolidApiClient : IApiClient<SolidApiClientConfiguration, SolidOrder>
{
public SolidApiClientConfiguration Configuration { get; }
public IApiClientOrderConverter<SolidOrder> GetOrderConverter()
{
...
}
public async Task<IEnumerable<SolidOrder>> GetNewOrdersAsync()
{
...
}
}
There's a function I'm trying to call with the following signature:
protected async Task ProcessClients<T>(IEnumerable<IApiClientConfiguration> clientConfigs)
where T : IApiClient<IApiClientConfiguration, IApiClientOrder>
{
...
}
And I'm attempting to call it like so:
await ProcessClients<SolidApiClient>(clientsConfig);
But I'm unable to make the generic call using SolidApiClient due to the following error:
Error CS0311 The type 'SolidApiClient' cannot be used as type parameter 'T' in the generic type or method 'Function.ProcessClients(string, IEnumerable)'. There is no implicit reference conversion from 'SolidApiClient' to 'IApiClient<IApiClientConfiguration, IApiClientOrder>'.
I've seen a number of different questions posted here that are similar but I've not managed to find a resolution from the answers I've found so far so am reaching out in case someone spots something with my approach that I've missed.
I've also tried a few variations of my approach but just seem to move the issue around to different parts of the code, so believe I must be using a flawed approach with the interface classes and generics.