Inspired by dotnet show (#386)
* Changed the order of the projects, Web first to infer as startup. * Added encapsulated JSON serialization - and moved to System.Text.Json * Refactored a few minor updates out Co-authored-by: Eric Fleming <eric-fleming18@hotmail.com>
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
<PackageReference Include="Ardalis.GuardClauses" Version="1.5.0" />
|
||||
<PackageReference Include="Ardalis.Specification" Version="3.0.0" />
|
||||
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
|
||||
<PackageReference Include="System.Text.Json" Version="4.7.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
18
src/ApplicationCore/Extensions/JsonExtensions.cs
Normal file
18
src/ApplicationCore/Extensions/JsonExtensions.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Microsoft.eShopWeb
|
||||
{
|
||||
public static class JsonExtensions
|
||||
{
|
||||
private static readonly JsonSerializerOptions _jsonOptions = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
public static T FromJson<T>(this string json) =>
|
||||
JsonSerializer.Deserialize<T>(json, _jsonOptions);
|
||||
|
||||
public static string ToJson<T>(this T obj) =>
|
||||
JsonSerializer.Serialize<T>(obj, _jsonOptions);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user