| | | 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.Generic; |
| | | 5 | | using System.Reflection.Metadata; |
| | | 6 | | using System.Text.Json; |
| | | 7 | | using System.Text.Json.Serialization.Metadata; |
| | | 8 | | |
| | | 9 | | [assembly: MetadataUpdateHandler(typeof(JsonSerializerOptionsUpdateHandler))] |
| | | 10 | | |
| | | 11 | | #pragma warning disable IDE0060 |
| | | 12 | | |
| | | 13 | | namespace System.Text.Json |
| | | 14 | | { |
| | | 15 | | /// <summary>Handler used to clear JsonSerializerOptions reflection cache upon a metadata update.</summary> |
| | | 16 | | internal static class JsonSerializerOptionsUpdateHandler |
| | | 17 | | { |
| | | 18 | | public static void ClearCache(Type[]? types) |
| | 0 | 19 | | { |
| | | 20 | | // Ignore the types, and just clear out all reflection caches from serializer options. |
| | 0 | 21 | | foreach (KeyValuePair<JsonSerializerOptions, object?> options in JsonSerializerOptions.TrackedOptionsInstanc |
| | 0 | 22 | | { |
| | 0 | 23 | | options.Key.ClearCaches(); |
| | 0 | 24 | | } |
| | | 25 | | |
| | 0 | 26 | | DefaultJsonTypeInfoResolver.ClearMemberAccessorCaches(); |
| | 0 | 27 | | } |
| | | 28 | | } |
| | | 29 | | } |