diff --git a/DysonNetwork.Shared/Proto/GrpcTypeHelper.cs b/DysonNetwork.Shared/Proto/GrpcTypeHelper.cs index 3210342..03f2d53 100644 --- a/DysonNetwork.Shared/Proto/GrpcTypeHelper.cs +++ b/DysonNetwork.Shared/Proto/GrpcTypeHelper.cs @@ -14,7 +14,7 @@ namespace DysonNetwork.Shared.Proto; public abstract class GrpcTypeHelper { - private static readonly JsonSerializerOptions? SerializerOptions = new JsonSerializerOptions() + public static readonly JsonSerializerOptions? SerializerOptions = new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower, DefaultIgnoreCondition = JsonIgnoreCondition.Never, diff --git a/DysonNetwork.Sphere/WebReader/EmbeddableBase.cs b/DysonNetwork.Sphere/WebReader/EmbeddableBase.cs index d1a499a..6854a2f 100644 --- a/DysonNetwork.Sphere/WebReader/EmbeddableBase.cs +++ b/DysonNetwork.Sphere/WebReader/EmbeddableBase.cs @@ -1,5 +1,7 @@ using System.Reflection; +using System.Text.Json; using System.Text.Json.Serialization; +using DysonNetwork.Shared.Proto; namespace DysonNetwork.Sphere.WebReader; @@ -29,16 +31,7 @@ public abstract class EmbeddableBase public Dictionary ToDictionary() { - var dict = new Dictionary(); - foreach (var prop in GetType().GetProperties()) - { - if (prop.GetCustomAttribute() is not null) - continue; - var value = prop.GetValue(this); - if (value is null) continue; - dict[prop.Name] = value; - } - - return dict; + var jsonRaw = JsonSerializer.Serialize(this, GrpcTypeHelper.SerializerOptions); + return JsonSerializer.Deserialize>(jsonRaw, GrpcTypeHelper.SerializerOptions) ?? []; } } \ No newline at end of file