diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 8227ccb46..a61cbd408 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @irvinesunday @darrelmiller @zengin @gavinbarron @millicentachieng @MaggieKimani1 @andrueastman +* @irvinesunday @darrelmiller @gavinbarron @millicentachieng @MaggieKimani1 @andrueastman diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index 4ff96a2fb..9f1108bba 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -9,7 +9,7 @@ enable hidi ./../../artifacts - 1.4.11 + 1.4.12 OpenAPI.NET CLI tool for slicing OpenAPI documents true @@ -29,23 +29,23 @@ - - - - + + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + - + diff --git a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj index 5545dc84f..3ea08878d 100644 --- a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj +++ b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj @@ -12,7 +12,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/src/Microsoft.OpenApi/Extensions/StringExtensions.cs b/src/Microsoft.OpenApi/Extensions/StringExtensions.cs index 541523df5..00c26575e 100644 --- a/src/Microsoft.OpenApi/Extensions/StringExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/StringExtensions.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. - using System; +using System.Collections.Concurrent; using System.Diagnostics.CodeAnalysis; using System.Reflection; using Microsoft.OpenApi.Attributes; @@ -13,6 +13,8 @@ namespace Microsoft.OpenApi.Extensions /// public static class StringExtensions { + private static readonly ConcurrentDictionary> EnumDisplayCache = new(); + /// /// Gets the enum value based on the given enum type and display name. /// @@ -21,22 +23,28 @@ public static class StringExtensions { var type = typeof(T); if (!type.IsEnum) - { return default; - } + + var displayMap = EnumDisplayCache.GetOrAdd(type, _ => new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase)); + + if (displayMap.TryGetValue(displayName, out var cachedValue)) + return (T)cachedValue; + foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Static)) { - var displayAttribute = (DisplayAttribute)field.GetCustomAttribute(typeof(DisplayAttribute)); - if (displayAttribute != null && displayAttribute.Name == displayName) + var displayAttribute = field.GetCustomAttribute(); + if (displayAttribute != null && displayAttribute.Name.Equals(displayName, StringComparison.OrdinalIgnoreCase)) { - return (T)field.GetValue(null); + var enumValue = (T)field.GetValue(null); + displayMap.TryAdd(displayName, enumValue); + return enumValue; } } return default; } internal static string ToFirstCharacterLowerCase(this string input) - => string.IsNullOrEmpty(input) ? string.Empty : char.ToLowerInvariant(input[0]) + input.Substring(1); + => string.IsNullOrEmpty(input) ? string.Empty : char.ToLowerInvariant(input[0]) + input.Substring(1); } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj index d0740f052..ae5d9f577 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj +++ b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj @@ -24,7 +24,7 @@ - +