y
This commit is contained in:
commit
1ee49b8966
1125 files changed
+32542
No files matched your search
@@ -0,0 +1,27 @@
|
||||
using System.IO;
|
||||
using System.Text.Encodings.Web;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace NeoRF.EarthModels;
|
||||
|
||||
/// <summary>模型自己的 JSON 读写(不依赖启动器)。</summary>
|
||||
public static class ModelJson
|
||||
{
|
||||
public static readonly JsonSerializerOptions Options = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
WriteIndented = true,
|
||||
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
|
||||
AllowTrailingCommas = true,
|
||||
ReadCommentHandling = JsonCommentHandling.Skip
|
||||
};
|
||||
|
||||
public static T? Read<T>(string path)
|
||||
{
|
||||
if (!File.Exists(path)) return default;
|
||||
return JsonSerializer.Deserialize<T>(File.ReadAllText(path), Options);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user