diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Helpers/ReflectHelper.cs b/src/Adapter/MSTestAdapter.PlatformServices/Helpers/ReflectHelper.cs
index 81234c2c29..cd6c40f80c 100644
--- a/src/Adapter/MSTestAdapter.PlatformServices/Helpers/ReflectHelper.cs
+++ b/src/Adapter/MSTestAdapter.PlatformServices/Helpers/ReflectHelper.cs
@@ -6,6 +6,7 @@
#endif
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
+using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Helpers;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -145,41 +146,7 @@ internal static bool MatchReturnType(MethodInfo method, Type returnType)
/// The reflected type that owns .
/// Categories defined.
internal static string[] GetTestCategories(MemberInfo categoryAttributeProvider, Type owningType)
- {
- Attribute[] methodAttributes = GetCustomAttributesCached(categoryAttributeProvider);
- Attribute[] typeAttributes = GetCustomAttributesCached(owningType);
- Attribute[] assemblyAttributes = GetCustomAttributesCached(owningType.Assembly);
-
- // Avoid LINQ iterator allocations by iterating the cached attribute arrays directly.
- // This follows the same allocation-free pattern used by GetTestPropertiesAsTraits.
- List? categories = null;
-
- foreach (Attribute attribute in methodAttributes)
- {
- if (attribute is TestCategoryBaseAttribute categoryAttr)
- {
- (categories ??= []).AddRange(categoryAttr.TestCategories);
- }
- }
-
- foreach (Attribute attribute in typeAttributes)
- {
- if (attribute is TestCategoryBaseAttribute categoryAttr)
- {
- (categories ??= []).AddRange(categoryAttr.TestCategories);
- }
- }
-
- foreach (Attribute attribute in assemblyAttributes)
- {
- if (attribute is TestCategoryBaseAttribute categoryAttr)
- {
- (categories ??= []).AddRange(categoryAttr.TestCategories);
- }
- }
-
- return categories is null ? [] : [.. categories];
- }
+ => PlatformServiceProvider.Instance.ReflectionOperations.GetTestCategories(categoryAttributeProvider, owningType);
///
/// Gets the parallelization level set on an assembly.
@@ -232,52 +199,7 @@ internal static bool IsDoNotParallelizeSet(Assembly assembly)
/// The member to inspect.
/// List of traits.
internal static Trait[] GetTestPropertiesAsTraits(MethodInfo testPropertyProvider)
- {
- Attribute[] attributesFromMethod = GetCustomAttributesCached(testPropertyProvider);
- Attribute[] attributesFromClass = testPropertyProvider.ReflectedType is { } testClass ? GetCustomAttributesCached(testClass) : [];
- int countTestPropertyAttribute = 0;
- foreach (Attribute attribute in attributesFromMethod)
- {
- if (attribute is TestPropertyAttribute)
- {
- countTestPropertyAttribute++;
- }
- }
-
- foreach (Attribute attribute in attributesFromClass)
- {
- if (attribute is TestPropertyAttribute)
- {
- countTestPropertyAttribute++;
- }
- }
-
- if (countTestPropertyAttribute == 0)
- {
- // This is the common case that we optimize for. This method used to be an iterator (uses yield return) which is allocating unnecessarily in common cases.
- return [];
- }
-
- var traits = new Trait[countTestPropertyAttribute];
- int index = 0;
- foreach (Attribute attribute in attributesFromMethod)
- {
- if (attribute is TestPropertyAttribute testProperty)
- {
- traits[index++] = new Trait(testProperty.Name, testProperty.Value);
- }
- }
-
- foreach (Attribute attribute in attributesFromClass)
- {
- if (attribute is TestPropertyAttribute testProperty)
- {
- traits[index++] = new Trait(testProperty.Name, testProperty.Value);
- }
- }
-
- return traits;
- }
+ => PlatformServiceProvider.Instance.ReflectionOperations.GetTestPropertiesAsTraits(testPropertyProvider);
///
/// Get attribute defined on a method which is of given type of subtype of given type.