diff --git a/src/Microsoft.TestPlatform.ObjectModel/TestProperty/TestProperty.cs b/src/Microsoft.TestPlatform.ObjectModel/TestProperty/TestProperty.cs index 0d787bdd5f..7800b47924 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/TestProperty/TestProperty.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/TestProperty/TestProperty.cs @@ -2,6 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +#if !NETSTANDARD1_0 +using System.Collections.Concurrent; +#endif using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Globalization; @@ -20,7 +23,11 @@ namespace Microsoft.VisualStudio.TestPlatform.ObjectModel; public class TestProperty : IEquatable { private Type _valueType; +#if !NETSTANDARD1_0 + private static readonly ConcurrentDictionary TypeCache = new(); +#else private static readonly Dictionary TypeCache = new(); +#endif #if NETSTANDARD1_0 private static bool DisableFastJson { get; set; } = true; @@ -192,7 +199,11 @@ private Type GetType(string typeName) { if (type != null) { +#if !NETSTANDARD1_0 + TypeCache.TryAdd(typeName, type); +#else TypeCache[typeName] = type; +#endif return type; } } @@ -260,7 +271,11 @@ private Type GetType(string typeName) if (!DisableFastJson) { +#if !NETSTANDARD1_0 + TypeCache.TryAdd(typeName, type); +#else TypeCache[typeName] = type; +#endif } return type; }