| | | 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.Collections; |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using System.Diagnostics; |
| | | 7 | | using System.IO.Pipelines; |
| | | 8 | | using System.Runtime.ExceptionServices; |
| | | 9 | | using System.Runtime.InteropServices; |
| | | 10 | | using System.Text.Json.Serialization; |
| | | 11 | | using System.Text.Json.Serialization.Metadata; |
| | | 12 | | using System.Threading; |
| | | 13 | | using System.Threading.Tasks; |
| | | 14 | | |
| | | 15 | | namespace System.Text.Json |
| | | 16 | | { |
| | | 17 | | [StructLayout(LayoutKind.Auto)] |
| | | 18 | | [DebuggerDisplay("{DebuggerDisplay,nq}")] |
| | | 19 | | internal struct WriteStack |
| | | 20 | | { |
| | 0 | 21 | | public readonly int CurrentDepth => _count; |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Exposes the stack frame that is currently active. |
| | | 25 | | /// </summary> |
| | | 26 | | public WriteStackFrame Current; |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Gets the parent stack frame, if it exists. |
| | | 30 | | /// </summary> |
| | | 31 | | public readonly ref WriteStackFrame Parent |
| | | 32 | | { |
| | | 33 | | get |
| | | 34 | | { |
| | | 35 | | Debug.Assert(_count - _indexOffset > 0); |
| | | 36 | | Debug.Assert(_stack is not null); |
| | | 37 | | return ref _stack[_count - _indexOffset - 1]; |
| | | 38 | | } |
| | | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Buffer containing all frames in the stack. For performance it is only populated for serialization depths > 1 |
| | | 43 | | /// </summary> |
| | | 44 | | private WriteStackFrame[] _stack; |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Tracks the current depth of the stack. |
| | | 48 | | /// </summary> |
| | | 49 | | private int _count; |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// If not zero, indicates that the stack is part of a re-entrant continuation of given depth. |
| | | 53 | | /// </summary> |
| | | 54 | | private int _continuationCount; |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Offset used to derive the index of the current frame in the stack buffer from the current value of <see cref |
| | | 58 | | /// following the formula currentIndex := _count - _indexOffset. |
| | | 59 | | /// Value can vary between 0 or 1 depending on whether we need to allocate a new frame on the first Push() opera |
| | | 60 | | /// which can happen if the root converter is polymorphic. |
| | | 61 | | /// </summary> |
| | | 62 | | private byte _indexOffset; |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// Cancellation token used by converters performing async serialization (e.g. IAsyncEnumerable) |
| | | 66 | | /// </summary> |
| | | 67 | | public CancellationToken CancellationToken; |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// In the case of async serialization, used by resumable converters to signal that |
| | | 71 | | /// the current buffer contents should not be flushed to the underlying stream. |
| | | 72 | | /// </summary> |
| | | 73 | | public bool SuppressFlush; |
| | | 74 | | |
| | | 75 | | /// <summary> |
| | | 76 | | /// Stores a pending task that a resumable converter depends on to continue work. |
| | | 77 | | /// It must be awaited by the root context before serialization is resumed. |
| | | 78 | | /// </summary> |
| | | 79 | | public Task? PendingTask; |
| | | 80 | | |
| | | 81 | | /// <summary> |
| | | 82 | | /// List of completed IAsyncDisposables that have been scheduled for disposal by converters. |
| | | 83 | | /// </summary> |
| | | 84 | | public List<IAsyncDisposable>? CompletedAsyncDisposables; |
| | | 85 | | |
| | | 86 | | /// <summary> |
| | | 87 | | /// The amount of bytes to write before the underlying Stream should be flushed and the |
| | | 88 | | /// current buffer adjusted to remove the processed bytes. |
| | | 89 | | /// </summary> |
| | | 90 | | public int FlushThreshold; |
| | | 91 | | |
| | | 92 | | public PipeWriter? PipeWriter; |
| | | 93 | | |
| | | 94 | | /// <summary> |
| | | 95 | | /// Indicates that the state still contains suspended frames waiting re-entry. |
| | | 96 | | /// </summary> |
| | 0 | 97 | | public readonly bool IsContinuation => _continuationCount != 0; |
| | | 98 | | |
| | | 99 | | // The bag of preservable references. |
| | | 100 | | public ReferenceResolver ReferenceResolver; |
| | | 101 | | |
| | | 102 | | /// <summary> |
| | | 103 | | /// Internal flag to let us know that we need to read ahead in the inner read loop. |
| | | 104 | | /// </summary> |
| | | 105 | | public bool SupportContinuation; |
| | | 106 | | |
| | | 107 | | /// <summary> |
| | | 108 | | /// Internal flag indicating that async serialization is supported. Implies `SupportContinuation`. |
| | | 109 | | /// </summary> |
| | | 110 | | public bool SupportAsync; |
| | | 111 | | |
| | | 112 | | /// <summary> |
| | | 113 | | /// Stores a reference id that has been calculated for a newly serialized object. |
| | | 114 | | /// </summary> |
| | | 115 | | public string? NewReferenceId; |
| | | 116 | | |
| | | 117 | | /// <summary> |
| | | 118 | | /// Indicates that the next converter is polymorphic and must serialize a type discriminator. |
| | | 119 | | /// </summary> |
| | | 120 | | public object? PolymorphicTypeDiscriminator; |
| | | 121 | | |
| | | 122 | | /// <summary> |
| | | 123 | | /// The polymorphic type resolver used by the next converter. |
| | | 124 | | /// </summary> |
| | | 125 | | public PolymorphicTypeResolver? PolymorphicTypeResolver; |
| | | 126 | | |
| | | 127 | | /// <summary> |
| | | 128 | | /// Whether the current frame needs to write out any metadata. |
| | | 129 | | /// </summary> |
| | 0 | 130 | | public readonly bool CurrentContainsMetadata => NewReferenceId != null || PolymorphicTypeDiscriminator != null; |
| | | 131 | | |
| | | 132 | | private void EnsurePushCapacity() |
| | 0 | 133 | | { |
| | 0 | 134 | | if (_stack is null) |
| | 0 | 135 | | { |
| | 0 | 136 | | _stack = new WriteStackFrame[4]; |
| | 0 | 137 | | } |
| | 0 | 138 | | else if (_count - _indexOffset == _stack.Length) |
| | 0 | 139 | | { |
| | 0 | 140 | | Array.Resize(ref _stack, 2 * _stack.Length); |
| | 0 | 141 | | } |
| | 0 | 142 | | } |
| | | 143 | | |
| | | 144 | | internal void Initialize( |
| | | 145 | | JsonTypeInfo jsonTypeInfo, |
| | | 146 | | object? rootValueBoxed = null, |
| | | 147 | | bool supportContinuation = false, |
| | | 148 | | bool supportAsync = false) |
| | 0 | 149 | | { |
| | 0 | 150 | | Debug.Assert(!supportAsync || supportContinuation, "supportAsync must imply supportContinuation"); |
| | 0 | 151 | | Debug.Assert(!IsContinuation); |
| | 0 | 152 | | Debug.Assert(CurrentDepth == 0); |
| | | 153 | | |
| | 0 | 154 | | Current.JsonTypeInfo = jsonTypeInfo; |
| | 0 | 155 | | Current.JsonPropertyInfo = jsonTypeInfo.PropertyInfoForTypeInfo; |
| | 0 | 156 | | Current.NumberHandling = Current.JsonPropertyInfo.EffectiveNumberHandling; |
| | 0 | 157 | | SupportContinuation = supportContinuation; |
| | 0 | 158 | | SupportAsync = supportAsync; |
| | | 159 | | |
| | 0 | 160 | | JsonSerializerOptions options = jsonTypeInfo.Options; |
| | 0 | 161 | | if (options.ReferenceHandlingStrategy != JsonKnownReferenceHandler.Unspecified) |
| | 0 | 162 | | { |
| | 0 | 163 | | Debug.Assert(options.ReferenceHandler != null); |
| | 0 | 164 | | ReferenceResolver = options.ReferenceHandler.CreateResolver(writing: true); |
| | | 165 | | |
| | 0 | 166 | | if (options.ReferenceHandlingStrategy == JsonKnownReferenceHandler.IgnoreCycles && |
| | 0 | 167 | | rootValueBoxed is not null && jsonTypeInfo.Type.IsValueType) |
| | 0 | 168 | | { |
| | | 169 | | // Root object is a boxed value type, we need to push it to the reference stack before starting the |
| | 0 | 170 | | ReferenceResolver.PushReferenceForCycleDetection(rootValueBoxed); |
| | 0 | 171 | | } |
| | 0 | 172 | | } |
| | 0 | 173 | | } |
| | | 174 | | |
| | | 175 | | /// <summary> |
| | | 176 | | /// Gets the nested JsonTypeInfo before resolving any polymorphic converters |
| | | 177 | | /// </summary> |
| | | 178 | | public readonly JsonTypeInfo PeekNestedJsonTypeInfo() |
| | 0 | 179 | | { |
| | 0 | 180 | | Debug.Assert(Current.PolymorphicSerializationState != PolymorphicSerializationState.PolymorphicReEntryStarte |
| | 0 | 181 | | return _count == 0 ? Current.JsonTypeInfo : Current.JsonPropertyInfo!.JsonTypeInfo; |
| | 0 | 182 | | } |
| | | 183 | | |
| | | 184 | | public void Push() |
| | 0 | 185 | | { |
| | 0 | 186 | | Debug.Assert(_continuationCount == 0 || _count < _continuationCount); |
| | | 187 | | |
| | 0 | 188 | | if (_continuationCount == 0) |
| | 0 | 189 | | { |
| | 0 | 190 | | Debug.Assert(Current.PolymorphicSerializationState != PolymorphicSerializationState.PolymorphicReEntrySu |
| | | 191 | | |
| | 0 | 192 | | if (_count == 0 && Current.PolymorphicSerializationState == PolymorphicSerializationState.None) |
| | 0 | 193 | | { |
| | | 194 | | // Perf enhancement: do not create a new stackframe on the first push operation |
| | | 195 | | // unless the converter has primed the current frame for polymorphic dispatch. |
| | 0 | 196 | | _count = 1; |
| | 0 | 197 | | _indexOffset = 1; // currentIndex := _count - 1; |
| | 0 | 198 | | } |
| | | 199 | | else |
| | 0 | 200 | | { |
| | 0 | 201 | | JsonTypeInfo jsonTypeInfo = Current.GetNestedJsonTypeInfo(); |
| | 0 | 202 | | JsonNumberHandling? numberHandling = Current.NumberHandling; |
| | | 203 | | |
| | 0 | 204 | | EnsurePushCapacity(); |
| | 0 | 205 | | _stack[_count - _indexOffset] = Current; |
| | 0 | 206 | | Current = default; |
| | 0 | 207 | | _count++; |
| | | 208 | | |
| | 0 | 209 | | Current.JsonTypeInfo = jsonTypeInfo; |
| | 0 | 210 | | Current.JsonPropertyInfo = jsonTypeInfo.PropertyInfoForTypeInfo; |
| | | 211 | | // Allow number handling on property to win over handling on type. |
| | 0 | 212 | | Current.NumberHandling = numberHandling ?? Current.JsonPropertyInfo.EffectiveNumberHandling; |
| | 0 | 213 | | } |
| | 0 | 214 | | } |
| | | 215 | | else |
| | 0 | 216 | | { |
| | | 217 | | // We are re-entering a continuation, adjust indices accordingly |
| | 0 | 218 | | if (_count++ > 0 || _indexOffset == 0) |
| | 0 | 219 | | { |
| | 0 | 220 | | Current = _stack[_count - _indexOffset]; |
| | 0 | 221 | | } |
| | | 222 | | |
| | | 223 | | // check if we are done |
| | 0 | 224 | | if (_continuationCount == _count) |
| | 0 | 225 | | { |
| | 0 | 226 | | _continuationCount = 0; |
| | 0 | 227 | | } |
| | 0 | 228 | | } |
| | | 229 | | |
| | | 230 | | #if DEBUG |
| | | 231 | | // Ensure the method is always exercised in debug builds. |
| | 0 | 232 | | _ = PropertyPath(); |
| | | 233 | | #endif |
| | 0 | 234 | | } |
| | | 235 | | |
| | | 236 | | public void Pop(bool success) |
| | 0 | 237 | | { |
| | 0 | 238 | | Debug.Assert(_count > 0); |
| | 0 | 239 | | Debug.Assert(_continuationCount == 0 || _count < _continuationCount); |
| | | 240 | | |
| | 0 | 241 | | if (!success) |
| | 0 | 242 | | { |
| | | 243 | | // Check if we need to initialize the continuation. |
| | 0 | 244 | | if (_continuationCount == 0) |
| | 0 | 245 | | { |
| | 0 | 246 | | if (_count == 1 && _indexOffset > 0) |
| | 0 | 247 | | { |
| | | 248 | | // No need to copy any frames here. |
| | 0 | 249 | | _continuationCount = 1; |
| | 0 | 250 | | _count = 0; |
| | 0 | 251 | | return; |
| | | 252 | | } |
| | | 253 | | |
| | | 254 | | // Need to push the Current frame to the stack, |
| | | 255 | | // ensure that we have sufficient capacity. |
| | 0 | 256 | | EnsurePushCapacity(); |
| | 0 | 257 | | _continuationCount = _count--; |
| | 0 | 258 | | } |
| | 0 | 259 | | else if (--_count == 0 && _indexOffset > 0) |
| | 0 | 260 | | { |
| | | 261 | | // reached the root, no need to copy frames. |
| | 0 | 262 | | return; |
| | | 263 | | } |
| | | 264 | | |
| | 0 | 265 | | int currentIndex = _count - _indexOffset; |
| | 0 | 266 | | _stack[currentIndex + 1] = Current; |
| | 0 | 267 | | Current = _stack[currentIndex]; |
| | 0 | 268 | | } |
| | | 269 | | else |
| | 0 | 270 | | { |
| | 0 | 271 | | Debug.Assert(_continuationCount == 0); |
| | | 272 | | |
| | 0 | 273 | | if (--_count > 0 || _indexOffset == 0) |
| | 0 | 274 | | { |
| | 0 | 275 | | Current = _stack[_count - _indexOffset]; |
| | 0 | 276 | | } |
| | 0 | 277 | | } |
| | 0 | 278 | | } |
| | | 279 | | |
| | | 280 | | public void AddCompletedAsyncDisposable(IAsyncDisposable asyncDisposable) |
| | 0 | 281 | | => (CompletedAsyncDisposables ??= new List<IAsyncDisposable>()).Add(asyncDisposable); |
| | | 282 | | |
| | | 283 | | // Asynchronously dispose of any AsyncDisposables that have been scheduled for disposal |
| | | 284 | | public readonly async ValueTask DisposeCompletedAsyncDisposables() |
| | 0 | 285 | | { |
| | 0 | 286 | | Debug.Assert(CompletedAsyncDisposables?.Count > 0); |
| | 0 | 287 | | Exception? exception = null; |
| | | 288 | | |
| | 0 | 289 | | foreach (IAsyncDisposable asyncDisposable in CompletedAsyncDisposables) |
| | 0 | 290 | | { |
| | | 291 | | try |
| | 0 | 292 | | { |
| | 0 | 293 | | await asyncDisposable.DisposeAsync().ConfigureAwait(false); |
| | 0 | 294 | | } |
| | 0 | 295 | | catch (Exception e) |
| | 0 | 296 | | { |
| | 0 | 297 | | exception = e; |
| | 0 | 298 | | } |
| | 0 | 299 | | } |
| | | 300 | | |
| | 0 | 301 | | if (exception is not null) |
| | 0 | 302 | | { |
| | 0 | 303 | | ExceptionDispatchInfo.Capture(exception).Throw(); |
| | | 304 | | } |
| | | 305 | | |
| | 0 | 306 | | CompletedAsyncDisposables.Clear(); |
| | 0 | 307 | | } |
| | | 308 | | |
| | | 309 | | /// <summary> |
| | | 310 | | /// Walks the stack cleaning up any leftover IDisposables |
| | | 311 | | /// in the event of an exception on serialization |
| | | 312 | | /// </summary> |
| | | 313 | | public readonly void DisposePendingDisposablesOnException() |
| | 0 | 314 | | { |
| | 0 | 315 | | Exception? exception = null; |
| | | 316 | | |
| | 0 | 317 | | Debug.Assert(Current.AsyncDisposable is null); |
| | 0 | 318 | | DisposeFrame(Current.CollectionEnumerator, ref exception); |
| | | 319 | | |
| | 0 | 320 | | if (_stack is not null) |
| | 0 | 321 | | { |
| | 0 | 322 | | int currentIndex = _count - _indexOffset; |
| | 0 | 323 | | int stackSize = Math.Max(currentIndex, _continuationCount); |
| | 0 | 324 | | for (int i = 0; i < stackSize; i++) |
| | 0 | 325 | | { |
| | 0 | 326 | | Debug.Assert(_stack[i].AsyncDisposable is null); |
| | | 327 | | |
| | 0 | 328 | | if (i == currentIndex) |
| | 0 | 329 | | { |
| | | 330 | | // Matches the entry in Current, skip to avoid double disposal. |
| | 0 | 331 | | Debug.Assert(_stack[i].CollectionEnumerator is null || ReferenceEquals(Current.CollectionEnumera |
| | 0 | 332 | | continue; |
| | | 333 | | } |
| | | 334 | | |
| | 0 | 335 | | DisposeFrame(_stack[i].CollectionEnumerator, ref exception); |
| | 0 | 336 | | } |
| | 0 | 337 | | } |
| | | 338 | | |
| | 0 | 339 | | if (exception is not null) |
| | 0 | 340 | | { |
| | 0 | 341 | | ExceptionDispatchInfo.Capture(exception).Throw(); |
| | | 342 | | } |
| | | 343 | | |
| | | 344 | | static void DisposeFrame(IEnumerator? collectionEnumerator, ref Exception? exception) |
| | 0 | 345 | | { |
| | | 346 | | try |
| | 0 | 347 | | { |
| | 0 | 348 | | if (collectionEnumerator is IDisposable disposable) |
| | 0 | 349 | | { |
| | 0 | 350 | | disposable.Dispose(); |
| | 0 | 351 | | } |
| | 0 | 352 | | } |
| | 0 | 353 | | catch (Exception e) |
| | 0 | 354 | | { |
| | 0 | 355 | | exception = e; |
| | 0 | 356 | | } |
| | 0 | 357 | | } |
| | 0 | 358 | | } |
| | | 359 | | |
| | | 360 | | /// <summary> |
| | | 361 | | /// Walks the stack cleaning up any leftover I(Async)Disposables |
| | | 362 | | /// in the event of an exception on async serialization |
| | | 363 | | /// </summary> |
| | | 364 | | public readonly async ValueTask DisposePendingDisposablesOnExceptionAsync() |
| | 0 | 365 | | { |
| | 0 | 366 | | Exception? exception = null; |
| | | 367 | | |
| | 0 | 368 | | exception = await DisposeFrame(Current.CollectionEnumerator, Current.AsyncDisposable, exception).ConfigureAw |
| | | 369 | | |
| | 0 | 370 | | if (_stack is not null) |
| | 0 | 371 | | { |
| | 0 | 372 | | Debug.Assert(_continuationCount == 0 || _count < _continuationCount); |
| | 0 | 373 | | int currentIndex = _count - _indexOffset; |
| | 0 | 374 | | int stackSize = Math.Max(currentIndex, _continuationCount); |
| | 0 | 375 | | for (int i = 0; i < stackSize; i++) |
| | 0 | 376 | | { |
| | 0 | 377 | | if (i == currentIndex) |
| | 0 | 378 | | { |
| | | 379 | | // Matches the entry in Current, skip to avoid double disposal. |
| | 0 | 380 | | Debug.Assert(_stack[i].CollectionEnumerator is null || ReferenceEquals(Current.CollectionEnumera |
| | 0 | 381 | | Debug.Assert(_stack[i].AsyncDisposable is null || ReferenceEquals(Current.AsyncDisposable, _stac |
| | 0 | 382 | | continue; |
| | | 383 | | } |
| | | 384 | | |
| | 0 | 385 | | exception = await DisposeFrame(_stack[i].CollectionEnumerator, _stack[i].AsyncDisposable, exception) |
| | 0 | 386 | | } |
| | 0 | 387 | | } |
| | | 388 | | |
| | 0 | 389 | | if (exception is not null) |
| | 0 | 390 | | { |
| | 0 | 391 | | ExceptionDispatchInfo.Capture(exception).Throw(); |
| | | 392 | | } |
| | | 393 | | |
| | | 394 | | static async ValueTask<Exception?> DisposeFrame(IEnumerator? collectionEnumerator, IAsyncDisposable? asyncDi |
| | 0 | 395 | | { |
| | 0 | 396 | | Debug.Assert(!(collectionEnumerator is not null && asyncDisposable is not null)); |
| | | 397 | | |
| | | 398 | | try |
| | 0 | 399 | | { |
| | 0 | 400 | | if (collectionEnumerator is IDisposable disposable) |
| | 0 | 401 | | { |
| | 0 | 402 | | disposable.Dispose(); |
| | 0 | 403 | | } |
| | 0 | 404 | | else if (asyncDisposable is not null) |
| | 0 | 405 | | { |
| | 0 | 406 | | await asyncDisposable.DisposeAsync().ConfigureAwait(false); |
| | 0 | 407 | | } |
| | 0 | 408 | | } |
| | 0 | 409 | | catch (Exception e) |
| | 0 | 410 | | { |
| | 0 | 411 | | exception = e; |
| | 0 | 412 | | } |
| | | 413 | | |
| | 0 | 414 | | return exception; |
| | 0 | 415 | | } |
| | 0 | 416 | | } |
| | | 417 | | |
| | | 418 | | // Return a property path as a simple JSONPath using dot-notation when possible. When special characters are pre |
| | | 419 | | // $.x.y.z |
| | | 420 | | // $['PropertyName.With.Special.Chars'] |
| | | 421 | | public string PropertyPath() |
| | 0 | 422 | | { |
| | 0 | 423 | | StringBuilder sb = new StringBuilder("$"); |
| | | 424 | | |
| | 0 | 425 | | (int frameCount, bool includeCurrentFrame) = _continuationCount switch |
| | 0 | 426 | | { |
| | 0 | 427 | | 0 => (_count - 1, true), // Not a continuation, report previous frames and Current. |
| | 0 | 428 | | 1 => (0, true), // Continuation of depth 1, just report Current frame. |
| | 0 | 429 | | int c => (c, false) // Continuation of depth > 1, report the entire stack. |
| | 0 | 430 | | }; |
| | | 431 | | |
| | 0 | 432 | | for (int i = 1; i <= frameCount; i++) |
| | 0 | 433 | | { |
| | 0 | 434 | | AppendStackFrame(sb, ref _stack[i - _indexOffset]); |
| | 0 | 435 | | } |
| | | 436 | | |
| | 0 | 437 | | if (includeCurrentFrame) |
| | 0 | 438 | | { |
| | 0 | 439 | | AppendStackFrame(sb, ref Current); |
| | 0 | 440 | | } |
| | | 441 | | |
| | 0 | 442 | | return sb.ToString(); |
| | | 443 | | |
| | | 444 | | static void AppendStackFrame(StringBuilder sb, ref WriteStackFrame frame) |
| | 0 | 445 | | { |
| | | 446 | | // Append the property name. Or attempt to get the JSON property name from the property name specified i |
| | 0 | 447 | | string? propertyName = |
| | 0 | 448 | | frame.JsonPropertyInfo?.MemberName ?? |
| | 0 | 449 | | frame.JsonPropertyNameAsString; |
| | | 450 | | |
| | 0 | 451 | | AppendPropertyName(sb, propertyName); |
| | 0 | 452 | | } |
| | | 453 | | |
| | | 454 | | static void AppendPropertyName(StringBuilder sb, string? propertyName) |
| | 0 | 455 | | { |
| | 0 | 456 | | if (propertyName != null) |
| | 0 | 457 | | { |
| | 0 | 458 | | if (propertyName.AsSpan().ContainsSpecialCharacters()) |
| | 0 | 459 | | { |
| | 0 | 460 | | sb.Append(@"['"); |
| | 0 | 461 | | sb.AppendEscapedPropertyName(propertyName); |
| | 0 | 462 | | sb.Append(@"']"); |
| | 0 | 463 | | } |
| | | 464 | | else |
| | 0 | 465 | | { |
| | 0 | 466 | | sb.Append('.'); |
| | 0 | 467 | | sb.Append(propertyName); |
| | 0 | 468 | | } |
| | 0 | 469 | | } |
| | 0 | 470 | | } |
| | 0 | 471 | | } |
| | | 472 | | |
| | | 473 | | [DebuggerBrowsable(DebuggerBrowsableState.Never)] |
| | 0 | 474 | | private string DebuggerDisplay => $"Path = {PropertyPath()} Current = ConverterStrategy.{Current.JsonPropertyInf |
| | | 475 | | } |
| | | 476 | | } |