You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
633 B
25 lines
633 B
using Newtonsoft.Json;
|
|
|
|
namespace Infrastructure.Extensions
|
|
{
|
|
public static class JsonExtensions
|
|
{
|
|
public static string ToJson(this object value)
|
|
{
|
|
return JsonConvert.SerializeObject(value, GetSettings());
|
|
}
|
|
|
|
public static T FromJson<T>(this string json)
|
|
{
|
|
return JsonConvert.DeserializeObject<T>(json, GetSettings());
|
|
}
|
|
|
|
private static JsonSerializerSettings GetSettings()
|
|
{
|
|
return new JsonSerializerSettings
|
|
{
|
|
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
|
|
};
|
|
}
|
|
}
|
|
} |