| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Diagnostics; |
| | | 5 | | using System.Text.Json.Nodes; |
| | | 6 | | using System.Text.Json.Serialization.Metadata; |
| | | 7 | | |
| | | 8 | | namespace System.Text.Json.Serialization.Converters |
| | | 9 | | { |
| | | 10 | | internal sealed class JsonNodeConverterFactory : JsonConverterFactory |
| | | 11 | | { |
| | 1 | 12 | | private static readonly JsonArrayConverter s_arrayConverter = new JsonArrayConverter(); |
| | 1 | 13 | | private static readonly JsonObjectConverter s_objectConverter = new JsonObjectConverter(); |
| | 1 | 14 | | private static readonly JsonValueConverter s_valueConverter = new JsonValueConverter(); |
| | | 15 | | |
| | | 16 | | public override JsonConverter? CreateConverter(Type typeToConvert, JsonSerializerOptions options) |
| | 1076 | 17 | | { |
| | 1076 | 18 | | if (typeof(JsonValue).IsAssignableFrom(typeToConvert)) |
| | 269 | 19 | | { |
| | 269 | 20 | | return s_valueConverter; |
| | | 21 | | } |
| | | 22 | | |
| | 807 | 23 | | if (typeof(JsonObject) == typeToConvert) |
| | 269 | 24 | | { |
| | 269 | 25 | | return s_objectConverter; |
| | | 26 | | } |
| | | 27 | | |
| | 538 | 28 | | if (typeof(JsonArray) == typeToConvert) |
| | 269 | 29 | | { |
| | 269 | 30 | | return s_arrayConverter; |
| | | 31 | | } |
| | | 32 | | |
| | 269 | 33 | | Debug.Assert(typeof(JsonNode) == typeToConvert); |
| | 269 | 34 | | return JsonNodeConverter.Instance; |
| | 1076 | 35 | | } |
| | | 36 | | |
| | 4453 | 37 | | public override bool CanConvert(Type typeToConvert) => typeof(JsonNode).IsAssignableFrom(typeToConvert); |
| | | 38 | | } |
| | | 39 | | } |