Answer the question
In order to leave comments, you need to log in
How to return string from c# generic?
Good afternoon,
I wrote a wrapper class for http calls with a dynamic type:
public async Task<T> PostPandaSpecified<T>(string pandaParams, string method)
{
// вырезал http вызов
var content = await response.Content.ReadAsStringAsync();
if (response.IsSuccessStatusCode)
{
if (typeof(T) == typeof(string))
{
return content; // ошибка
}
else
{
var res = JsonConvert.DeserializeObject<T>(content);
return res;
}
}
throw new HttpRequestException(content);
}
var res = await PostPandaSpecified<SomeResultClass>(dataToSend, "url");
var res = await PostPandaSpecified<string>(dataToSend, "url");
// Ошибка в этом блоке
if (typeof(T) == typeof(string))
{
return content; // Cannot implicity convert type 'string' to 'T'
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question