powershell/resources/runtime/csharp/json/Models/JsonModelCache.cs (12 lines of code) (raw):

/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ using System; using System.Runtime.CompilerServices; namespace Carbon.Json { internal static class JsonModelCache { private static readonly ConditionalWeakTable<Type, JsonModel> cache = new ConditionalWeakTable<Type, JsonModel>(); public static JsonModel Get(Type type) => cache.GetValue(type, Create); private static JsonModel Create(Type type) => JsonModel.FromType(type); } }