From 20d4ee32a21b4ede7857a13950a9c681ee463c22 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Tue, 12 Aug 2025 20:29:59 +0200 Subject: [PATCH 1/2] Do half the work in GetManagedName --- .../ManagedNameHelper.Reflection.cs | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs b/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs index b5c931be59..f820eadbc5 100644 --- a/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs +++ b/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs @@ -80,8 +80,18 @@ public static void GetManagedName(MethodBase method, out string managedTypeName, /// public static void GetManagedName(MethodBase method, out string managedTypeName, out string managedMethodName, out string?[] hierarchyValues) { - GetManagedName(method, out managedTypeName, out managedMethodName); - GetManagedNameAndHierarchy(method, true, out _, out _, out hierarchyValues); + if (!method.IsGenericMethod && ReflectionHelpers.GetReflectedType(method) is { } reflectedType && !ReflectionHelpers.IsGenericType(semanticType)) + { + // We are dealing with non-generic method in non-generic type. + // So, it doesn't matter what we pass as "useClosedTypes". + // Instead of calling GetManagedNameAndHierarchy that does repeated work, we call it only once. + GetManagedNameAndHierarchy(method, false, out managedTypeName, out managedMethodName, out hierarchyValues); + } + else + { + GetManagedNameAndHierarchy(method, false, out managedTypeName, out managedMethodName, out _); + GetManagedNameAndHierarchy(method, true, out _, out _, out hierarchyValues); + } } /// @@ -344,7 +354,7 @@ bool Filter(MemberInfo mbr, object? param) hierarchies[1] = hierarchies[0]; } - AppendNestedTypeName(b, type, closedType); + AppendNestedTypeName(b, type); if (closedType) { AppendGenericTypeParameters(b, type); @@ -456,7 +466,7 @@ private static void NormalizeAndAppendString(StringBuilder b, string name) b.Append('\''); } - private static int AppendNestedTypeName(StringBuilder b, Type? type, bool closedType) + private static int AppendNestedTypeName(StringBuilder b, Type? type) { if (type is null) { @@ -466,7 +476,7 @@ private static int AppendNestedTypeName(StringBuilder b, Type? type, bool closed var outerArity = 0; if (type.IsNested) { - outerArity = AppendNestedTypeName(b, type.DeclaringType, closedType); + outerArity = AppendNestedTypeName(b, type.DeclaringType); b.Append('+'); } From e7434dc91fb43f35604a1e70681197e218892211 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Tue, 12 Aug 2025 20:43:04 +0200 Subject: [PATCH 2/2] Update ManagedNameHelper.Reflection.cs --- .../ManagedNameUtilities/ManagedNameHelper.Reflection.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs b/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs index f820eadbc5..66d097ed32 100644 --- a/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs +++ b/src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs @@ -80,7 +80,7 @@ public static void GetManagedName(MethodBase method, out string managedTypeName, /// public static void GetManagedName(MethodBase method, out string managedTypeName, out string managedMethodName, out string?[] hierarchyValues) { - if (!method.IsGenericMethod && ReflectionHelpers.GetReflectedType(method) is { } reflectedType && !ReflectionHelpers.IsGenericType(semanticType)) + if (!method.IsGenericMethod && ReflectionHelpers.GetReflectedType(method) is { } semanticType && !ReflectionHelpers.IsGenericType(semanticType)) { // We are dealing with non-generic method in non-generic type. // So, it doesn't matter what we pass as "useClosedTypes".