pschelpdesk/Vendor/Prise/Infrastructure/JsonSerializerResultConverter.cs
2024-11-05 09:18:22 +01:00

25 lines
747 B
C#

using System;
using Newtonsoft.Json;
using Prise.Proxy;
namespace Prise.Infrastructure
{
public class JsonSerializerResultConverter : ResultConverter
{
public override object Deserialize(Type localType, Type remoteType, object value)
{
// Get the local type
var resultType = localType;
// Check if the type is a Task<T>
if (localType.BaseType == typeof(System.Threading.Tasks.Task))
{
// Get the <T>
resultType = localType.GenericTypeArguments[0];
}
return value;
var ser = JsonConvert.SerializeObject(value);
return JsonConvert.DeserializeObject(ser, localType);
}
}
}