// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #if !NET6_0_OR_GREATER namespace System.Runtime.CompilerServices; /// /// Helper methods for the type. /// internal static class ConditionalWeakTableExtensions { /// /// Tries to add a new pair to the table. /// /// Tke key of items to store in the table. /// The values to store in the table. /// The input instance to modify. /// The key to add. /// The value to associate with key. public static bool TryAdd(this ConditionalWeakTable table, TKey key, TValue value) where TKey : class where TValue : class? { // There is no way to do this on .NET Standard 2.0 or 2.1 without exception handling try { table.Add(key, value); return true; } catch (ArgumentException) { return false; } } } #endif