|
|
|
@ -1,9 +1,9 @@
|
|
|
|
|
using Connected.Interop.Merging;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Text.Json.Nodes;
|
|
|
|
|
using Connected.Interop.Merging;
|
|
|
|
|
|
|
|
|
|
namespace Connected.Interop;
|
|
|
|
|
|
|
|
|
@ -41,12 +41,17 @@ public static class Serializer
|
|
|
|
|
using var ms = new MemoryStream();
|
|
|
|
|
using var writer = new Utf8JsonWriter(ms, new JsonWriterOptions { Indented = true, SkipValidation = false });
|
|
|
|
|
|
|
|
|
|
if (value is JsonNode json)
|
|
|
|
|
json.WriteTo(writer);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (value.GetType().IsEnumerable())
|
|
|
|
|
SerializeArray(writer, null, value);
|
|
|
|
|
else if (value.GetType().IsTypePrimitive())
|
|
|
|
|
SerializePrimitive(writer, value);
|
|
|
|
|
else
|
|
|
|
|
SerializeObject(writer, null, value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await writer.FlushAsync();
|
|
|
|
|
|
|
|
|
@ -78,18 +83,20 @@ public static class Serializer
|
|
|
|
|
if (value is null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var enumerable = property.GetValue(value) as IEnumerable;
|
|
|
|
|
|
|
|
|
|
if (enumerable is null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (property is not null)
|
|
|
|
|
writer.WriteStartArray(property.Name.ToCamelCase());
|
|
|
|
|
else
|
|
|
|
|
writer.WriteStartArray();
|
|
|
|
|
|
|
|
|
|
if (value is IEnumerable enumerable)
|
|
|
|
|
{
|
|
|
|
|
var enumerator = enumerable.GetEnumerator();
|
|
|
|
|
|
|
|
|
|
while (enumerator.MoveNext())
|
|
|
|
|
SerializeObject(writer, null, enumerator.Current);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
writer.WriteEndArray();
|
|
|
|
|
}
|
|
|
|
@ -100,11 +107,13 @@ public static class Serializer
|
|
|
|
|
SerializeArray(writer, property, value);
|
|
|
|
|
else if (!property.PropertyType.IsTypePrimitive())
|
|
|
|
|
SerializeObject(writer, property, value);
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
writer.WritePropertyName(property.Name.ToCamelCase());
|
|
|
|
|
|
|
|
|
|
SerializePrimitive(writer, property.GetValue(value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void SerializePrimitive(Utf8JsonWriter writer, object? value)
|
|
|
|
|
{
|
|
|
|
|