2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 13:33:13 +00:00

Added JSON

This commit is contained in:
2021-02-20 11:38:11 +03:00
parent df88317b1f
commit 7c707637de
14 changed files with 296 additions and 106 deletions

View File

@ -38,6 +38,9 @@ using System.Linq;
using Esiur.Core;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text.Json;
using Esiur.Resource;
using System.Text.Json.Serialization;
namespace Esiur.Misc
{
@ -58,6 +61,30 @@ namespace Esiur.Misc
public static event LogEvent SystemLog;
public static string ToJson(this IResource resource)
{
try
{
return JsonSerializer.Serialize(resource, Global.SerializeOptions);
}catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return "";
}
}
public static JsonSerializerOptions SerializeOptions = new JsonSerializerOptions
{
ReferenceHandler = ReferenceHandler.Preserve,
WriteIndented = true,
Converters =
{
new ResourceJsonConverter(),
new DoubleJsonConverter()
}
};
public static string Version { get; }= FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;