|
14 | 14 | using System.Collections;
|
15 | 15 | using System.Collections.Generic;
|
16 | 16 | using System.Threading;
|
17 |
| -using ServiceStack.Text.Json; |
18 | 17 |
|
19 | 18 | namespace ServiceStack.Text.Common
|
20 | 19 | {
|
@@ -51,13 +50,11 @@ public static ParseStringSpanDelegate GetParseStringSpanMethod(Type type)
|
51 | 50 |
|
52 | 51 | //optimized access for regularly used types
|
53 | 52 | if (type == typeof(Dictionary<string, string>))
|
54 |
| - { |
55 | 53 | return ParseStringDictionary;
|
56 |
| - } |
| 54 | + if (type == typeof(Dictionary<string, object>) && Json.JsonTypeSerializer.Instance.ObjectDeserializer != null) |
| 55 | + return s => Json.JsonTypeSerializer.Instance.ObjectDeserializer(s); |
57 | 56 | if (type == typeof(JsonObject))
|
58 |
| - { |
59 | 57 | return ParseJsonObject;
|
60 |
| - } |
61 | 58 | if (typeof(JsonObject).IsAssignableFrom(type))
|
62 | 59 | {
|
63 | 60 | var method = typeof(DeserializeDictionary<TSerializer>).GetMethod("ParseInheritedJsonObject");
|
@@ -89,7 +86,7 @@ public static ParseStringSpanDelegate GetParseStringSpanMethod(Type type)
|
89 | 86 |
|
90 | 87 | var result = new T();
|
91 | 88 |
|
92 |
| - if (JsonTypeSerializer.IsEmptyMap(value, index)) return result; |
| 89 | + if (Json.JsonTypeSerializer.IsEmptyMap(value, index)) return result; |
93 | 90 |
|
94 | 91 | var valueLength = value.Length;
|
95 | 92 | while (index < valueLength)
|
@@ -119,7 +116,7 @@ public static JsonObject ParseJsonObject(ReadOnlySpan<char> value)
|
119 | 116 |
|
120 | 117 | var result = new JsonObject();
|
121 | 118 |
|
122 |
| - if (JsonTypeSerializer.IsEmptyMap(value, index)) return result; |
| 119 | + if (Json.JsonTypeSerializer.IsEmptyMap(value, index)) return result; |
123 | 120 |
|
124 | 121 | var valueLength = value.Length;
|
125 | 122 | while (index < valueLength)
|
@@ -151,7 +148,7 @@ public static Dictionary<string, string> ParseStringDictionary(ReadOnlySpan<char
|
151 | 148 |
|
152 | 149 | var result = new Dictionary<string, string>();
|
153 | 150 |
|
154 |
| - if (JsonTypeSerializer.IsEmptyMap(value, index)) return result; |
| 151 | + if (Json.JsonTypeSerializer.IsEmptyMap(value, index)) return result; |
155 | 152 |
|
156 | 153 | var valueLength = value.Length;
|
157 | 154 | while (index < valueLength)
|
@@ -185,7 +182,7 @@ public static IDictionary ParseIDictionary(ReadOnlySpan<char> value, Type dictTy
|
185 | 182 |
|
186 | 183 | var to = (IDictionary)dictType.CreateInstance();
|
187 | 184 |
|
188 |
| - if (JsonTypeSerializer.IsEmptyMap(value, index)) return to; |
| 185 | + if (Json.JsonTypeSerializer.IsEmptyMap(value, index)) return to; |
189 | 186 |
|
190 | 187 | var valueLength = value.Length;
|
191 | 188 | while (index < valueLength)
|
@@ -245,7 +242,7 @@ public static IDictionary<TKey, TValue> ParseDictionary<TKey, TValue>(
|
245 | 242 | ? new Dictionary<TKey, TValue>()
|
246 | 243 | : (IDictionary<TKey, TValue>)createMapType.CreateInstance();
|
247 | 244 |
|
248 |
| - if (JsonTypeSerializer.IsEmptyMap(value, index)) return to; |
| 245 | + if (Json.JsonTypeSerializer.IsEmptyMap(value, index)) return to; |
249 | 246 |
|
250 | 247 | var valueLength = value.Length;
|
251 | 248 | while (index < valueLength)
|
@@ -339,8 +336,9 @@ public static object ParseDictionaryType(ReadOnlySpan<char> value, Type createMa
|
339 | 336 | do
|
340 | 337 | {
|
341 | 338 | snapshot = ParseDelegateCache;
|
342 |
| - newCache = new Dictionary<TypesKey, ParseDictionaryDelegate>(ParseDelegateCache); |
343 |
| - newCache[key] = parseDelegate; |
| 339 | + newCache = new Dictionary<TypesKey, ParseDictionaryDelegate>(ParseDelegateCache) { |
| 340 | + [key] = parseDelegate |
| 341 | + }; |
344 | 342 |
|
345 | 343 | } while (!ReferenceEquals(
|
346 | 344 | Interlocked.CompareExchange(ref ParseDelegateCache, newCache, snapshot), snapshot));
|
|
0 commit comments