/*
* Responsible for creating a success result of some sort.
*/
async Task <Response <TOut> > GetSuccessResult <TOut>(
net.HttpContent content,
Response <TOut> responseResult)
{
if (typeof(TOut) == typeof(byte[]) || typeof(TOut) == typeof(object))
{
var contentType = content.Headers.ContentType?.MediaType ?? "application/json";
switch (contentType)
{
case "application/json":
case "application/hyperlambda":
responseResult.Content = (TOut)(object)await content.ReadAsStringAsync();
break;
default:
if (contentType.StartsWith("text/"))
{
responseResult.Content = (TOut)(object)await content.ReadAsStringAsync();
}
else
{
responseResult.Content = (TOut)(object)await content.ReadAsByteArrayAsync();
}
break;
}
}
else if (typeof(TOut) == typeof(string))
{
responseResult.Content = (TOut)(object)await content.ReadAsStringAsync();
}
else if (typeof(IConvertible).IsAssignableFrom(typeof(TOut)))
{
var txtContent = await content.ReadAsStringAsync();
responseResult.Content = (TOut)Convert.ChangeType(txtContent, typeof(TOut));
}
else
{
var txtContent = await content.ReadAsStringAsync();
var objResult = JToken.Parse(txtContent);
responseResult.Content = objResult.ToObject <TOut>();
}
return(responseResult);
}