Exemplo n.º 1
0
        private static void _DeserializeExtensions(JsonSerializable parent, ref Utf8JsonReader reader, IList <JsonSerializable> extensions)
        {
            reader.Read();

            if (reader.TokenType == JsonToken.StartObject)
            {
                while (reader.Read() && reader.TokenType != JsonToken.EndObject)
                {
                    var key = reader.GetString();

                    var val = ExtensionsFactory.Create(parent, key);

                    if (val == null)
                    {
                        val = new UnknownNode(key);
                    }

                    val.Deserialize(ref reader);
                    extensions.Add(val);
                    continue;
                }
            }

            reader.Skip();
        }
Exemplo n.º 2
0
        private static IReadOnlyDictionary <string, JsonSerializable> _ToDictionary(JsonSerializable context, IEnumerable <JsonSerializable> serializables)
        {
            var dict = new Dictionary <string, JsonSerializable>();

            foreach (var val in serializables)
            {
                if (val == null)
                {
                    continue;
                }

                string key = null;

                if (val is UnknownNode unk)
                {
                    key = unk.Name;
                }
                else
                {
                    key = ExtensionsFactory.Identify(context.GetType(), val.GetType());
                }

                if (key == null)
                {
                    continue;
                }
                dict[key] = val;
            }

            return(dict);
        }