Reputation: 37
beloww is my interface
public interface IMyInterface
{
public Task<IApiResponseItem<T>> MyMethodt<T>(string inp1, string inp2,
string inp3="SqlKey", ApiMethod method = ApiMethod.Get,
TimeSpan? timeout = null) where T : new();
}
and implementation
public async Task<IApiResponseItem<T>> MyMethodt<T>(string inp1, string inp2,
string inp3="SqlKey", ApiMethod method = ApiMethod.Get,
TimeSpan? timeout = null) where T : new();
{
}
below is the call
var iApiResponse = await _resilentApi.MyMethodt(inp1, inp2, "SqlKey", ApiMethod.Get, timeout);
but, i always receiving error as
The type arguments for method 'IMyInterface.MyMethodt(string, string, string, ApiMethod, TimeSpan?)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
Upvotes: 1
Views: 2932
Reputation: 59503
You pass in a string
, a string
, a string
, an enum
and a TimeSpan
to the method. You never specified T
in the parameters of the method. How would the compiler be able to figure out what T
is? It could be anything.
There are 2 possible solutions.
you need to specify the type as part of the method call.
var iApiResponse = await _resilentApi.MyMethodt<Whatever>(inp1, inp2, "SqlKey", ApiMethod.Get, timeout);
^^^^^^^^
make T
part of the method signature somewhere
public async Task<IApiResponseItem<T>> MyMethodt<T>(string inp1, string inp2, T t,
string inp3 = "SqlKey", ApiMethod method = ApiMethod.Get, ^^^
TimeSpan? timeout = null) where T : new()
Upvotes: 0