Skip to content

Commit ec1176a

Browse files
authored
Do half the work in GetManagedName (#15255)
* Do half the work in GetManagedName * Update ManagedNameHelper.Reflection.cs
1 parent c9bbb52 commit ec1176a

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/Microsoft.TestPlatform.AdapterUtilities/ManagedNameUtilities/ManagedNameHelper.Reflection.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,18 @@ public static void GetManagedName(MethodBase method, out string managedTypeName,
8080
/// </remarks>
8181
public static void GetManagedName(MethodBase method, out string managedTypeName, out string managedMethodName, out string?[] hierarchyValues)
8282
{
83-
GetManagedName(method, out managedTypeName, out managedMethodName);
84-
GetManagedNameAndHierarchy(method, true, out _, out _, out hierarchyValues);
83+
if (!method.IsGenericMethod && ReflectionHelpers.GetReflectedType(method) is { } semanticType && !ReflectionHelpers.IsGenericType(semanticType))
84+
{
85+
// We are dealing with non-generic method in non-generic type.
86+
// So, it doesn't matter what we pass as "useClosedTypes".
87+
// Instead of calling GetManagedNameAndHierarchy that does repeated work, we call it only once.
88+
GetManagedNameAndHierarchy(method, false, out managedTypeName, out managedMethodName, out hierarchyValues);
89+
}
90+
else
91+
{
92+
GetManagedNameAndHierarchy(method, false, out managedTypeName, out managedMethodName, out _);
93+
GetManagedNameAndHierarchy(method, true, out _, out _, out hierarchyValues);
94+
}
8595
}
8696

8797
/// <summary>
@@ -344,7 +354,7 @@ bool Filter(MemberInfo mbr, object? param)
344354
hierarchies[1] = hierarchies[0];
345355
}
346356

347-
AppendNestedTypeName(b, type, closedType);
357+
AppendNestedTypeName(b, type);
348358
if (closedType)
349359
{
350360
AppendGenericTypeParameters(b, type);
@@ -456,7 +466,7 @@ private static void NormalizeAndAppendString(StringBuilder b, string name)
456466
b.Append('\'');
457467
}
458468

459-
private static int AppendNestedTypeName(StringBuilder b, Type? type, bool closedType)
469+
private static int AppendNestedTypeName(StringBuilder b, Type? type)
460470
{
461471
if (type is null)
462472
{
@@ -466,7 +476,7 @@ private static int AppendNestedTypeName(StringBuilder b, Type? type, bool closed
466476
var outerArity = 0;
467477
if (type.IsNested)
468478
{
469-
outerArity = AppendNestedTypeName(b, type.DeclaringType, closedType);
479+
outerArity = AppendNestedTypeName(b, type.DeclaringType);
470480
b.Append('+');
471481
}
472482

0 commit comments

Comments
 (0)