Add project
This commit is contained in:
11
Common/Extensions/JsonExtensions.cs
Normal file
11
Common/Extensions/JsonExtensions.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Common.Extensions
|
||||
{
|
||||
public static class JsonExtensions
|
||||
{
|
||||
private static JsonSerializerOptions _jso = new() { PropertyNameCaseInsensitive = true, PropertyNamingPolicy = JsonNamingPolicy.CamelCase };
|
||||
public static string ToJson<T>(this T source) => JsonSerializer.Serialize(source, _jso);
|
||||
public static T FromJson<T>(this string source) => JsonSerializer.Deserialize<T>(source, _jso) ?? default!;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user