Initial code commit.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using Sufi.Demo.PeopleDirectory.Shared.Wrapper;
|
||||
using System.Net.Http;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Sufi.Demo.PeopleDirectory.Shared.Extensions
|
||||
{
|
||||
public static class ResultExtensions
|
||||
{
|
||||
public static async Task<IResult<T>> ToResult<T>(this HttpResponseMessage response) where T : notnull
|
||||
{
|
||||
var responseAsString = await response.Content.ReadAsStringAsync();
|
||||
var responseObject = JsonSerializer.Deserialize<Result<T>>(responseAsString, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
ReferenceHandler = ReferenceHandler.Preserve
|
||||
});
|
||||
return responseObject!;
|
||||
}
|
||||
|
||||
public static async Task<IResult> ToResult(this HttpResponseMessage response)
|
||||
{
|
||||
var responseAsString = await response.Content.ReadAsStringAsync();
|
||||
var responseObject = JsonSerializer.Deserialize<Result>(responseAsString, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
ReferenceHandler = ReferenceHandler.Preserve
|
||||
});
|
||||
return responseObject!;
|
||||
}
|
||||
|
||||
public static async Task<PaginatedResult<T>> ToPaginatedResult<T>(this HttpResponseMessage response) where T : notnull
|
||||
{
|
||||
var responseAsString = await response.Content.ReadAsStringAsync();
|
||||
var responseObject = JsonSerializer.Deserialize<PaginatedResult<T>>(responseAsString, new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
});
|
||||
return responseObject!;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user