Browse Source

Remove unused serializer code

pull/333/head
Ionite 1 year ago
parent
commit
63e19b1742
No known key found for this signature in database
  1. 3
      StabilityMatrix.Avalonia/App.axaml.cs
  2. 36
      StabilityMatrix.Avalonia/Helpers/ViewModelSerializer.cs

3
StabilityMatrix.Avalonia/App.axaml.cs

@ -233,9 +233,6 @@ public sealed class App : Application
var services = ConfigureServices();
Services = services.BuildServiceProvider();
// Configure json serializers
ViewModelSerializer.SetServiceProvider(Services);
var settingsManager = Services.GetRequiredService<ISettingsManager>();
if (settingsManager.TryFindLibrary())

36
StabilityMatrix.Avalonia/Helpers/ViewModelSerializer.cs

@ -3,48 +3,12 @@ using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Reflection;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Newtonsoft.Json;
using StabilityMatrix.Avalonia.Converters.Json;
using JsonException = System.Text.Json.JsonException;
namespace StabilityMatrix.Avalonia.Helpers;
public static class ViewModelSerializer
{
public static JsonSerializerSettings SerializeSettings { get; } =
new()
{
Formatting = Formatting.Indented,
TypeNameHandling = TypeNameHandling.Arrays,
NullValueHandling = NullValueHandling.Ignore
};
public static JsonSerializerSettings DeserializeSettings { get; } =
new() { TypeNameHandling = TypeNameHandling.Arrays };
public static void SetServiceProvider(IServiceProvider serviceProvider)
{
SerializeSettings.ContractResolver = new ServiceProviderContractResolver(serviceProvider);
DeserializeSettings.ContractResolver = new ServiceProviderContractResolver(serviceProvider);
}
public static JsonObject SerializeToJsonObject<T>(T target)
{
var result = JsonConvert.SerializeObject(target, SerializeSettings);
return JsonNode.Parse(result)?.AsObject() ?? throw new JsonException();
}
public static T? DeserializeJsonObject<T>(JsonObject jsonObject)
{
var result = JsonConvert.DeserializeObject<T>(
jsonObject.ToJsonString(),
DeserializeSettings
);
return result;
}
public static IImmutableDictionary<string, Type> GetDerivedTypes(Type baseType)
{
return GetJsonDerivedTypeAttributes(baseType)

Loading…
Cancel
Save