// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. namespace System.Collections.Generic { internal static class DictionaryExtensions { public static TValue GetOrAdd(this IDictionary dictionary, TKey key, Func factory) { lock (dictionary) { TValue value; if (!dictionary.TryGetValue(key, out value)) { value = factory(key); dictionary[key] = value; } return value; } } } }