mirror of
				https://github.com/esiur/esiur-dotnet.git
				synced 2025-10-30 23:51:34 +00:00 
			
		
		
		
	Added JSON
This commit is contained in:
		| @@ -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; | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user