mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
* Use preview language version * Apply various code fixers * Remove TypeTreeHelper * Remove unused properties from IExportContainer
33 lines
1000 B
C#
33 lines
1000 B
C#
using System.Text.Encodings.Web;
|
|
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace AssetRipper.GUI.SourceGenerator;
|
|
|
|
[JsonSourceGenerationOptions(WriteIndented = true, IndentCharacter = ' ', IndentSize = 4, NewLine = "\n")]
|
|
[JsonSerializable(typeof(Dictionary<string, string>))]
|
|
internal sealed partial class DictionarySerializerContext : JsonSerializerContext
|
|
{
|
|
[field: MaybeNull]
|
|
private static DictionarySerializerContext ActualDefault
|
|
{
|
|
get
|
|
{
|
|
return field ??= new(new JsonSerializerOptions(s_defaultOptions!)
|
|
{
|
|
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
|
});
|
|
}
|
|
}
|
|
|
|
public static string Serialize(Dictionary<string, string> dictionary)
|
|
{
|
|
return JsonSerializer.Serialize(dictionary, ActualDefault.DictionaryStringString);
|
|
}
|
|
|
|
public static Dictionary<string, string> Deserialize(string json)
|
|
{
|
|
return JsonSerializer.Deserialize(json, ActualDefault.DictionaryStringString) ?? throw new("Json text could not be deserialized.");
|
|
}
|
|
}
|