Skip to content

[file-diet] Refactor TypeCache.cs — 1027-line file exceeds healthy size threshold #8741

@Evangelink

Description

@Evangelink

Overview

The file src/Adapter/MSTestAdapter.PlatformServices/Execution/TypeCache.cs has grown to 1027 lines, making it harder to navigate and maintain. This task involves refactoring it into smaller, more focused files.

Current State

  • File: src/Adapter/MSTestAdapter.PlatformServices/Execution/TypeCache.cs
  • Size: 1027 lines
  • Language: C#
Structural Analysis

The file contains a single internal sealed class TypeCache with the following responsibilities:

  1. Test method resolutionGetTestMethodInfo, GetTestMethodInfoForDiscovery, ResolveTestMethodInfo, ResolveTestMethodInfoForDiscovery, GetMethodInfoForTestMethod, GetMethodInfoUsingManagedNameHelper
  2. Class info cache managementGetClassInfo, CreateTestClassInfo, LoadType, CreateClassInfo
  3. Assembly info cache managementGetAssemblyInfo, CreateTestAssemblyInfo
  4. Fixture/provider discoveryDiscoverFixturesFromProviders, LoadProviderMarkers, ProcessProviderFixtureType, CollectFixtureMethodsFromProviderType, EnumerateCandidateAssemblies, TryLoadReferencedAssembly, HasAssemblyFixtureProviderMarker
  5. Initialization/cleanup detectionIsAssemblyOrClassInitializeMethod, IsAssemblyOrClassCleanupMethod, UpdateInfoWithInitializeAndCleanupMethods, UpdateInfoIfClassInitializeOrCleanupMethod, UpdateInfoIfTestInitializeOrCleanupMethod, TryGetTimeoutInfo
  6. HelpersIsFrameworkAssemblyName, SafeGetAssemblyName

Refactoring Strategy

Because TypeCache is internal sealed, C# partial classes are an idiomatic way to split it without any public-API changes.

Proposed File Splits

  1. TypeCache.cs (keep as the primary file)

    • Contents: fields, constructors, public properties, GetTestMethodInfo, GetTestMethodInfoForDiscovery, InitializeLifetimeService
    • Responsibility: Core entry points and state; under ~120 lines after extraction
  2. TypeCache.ClassInfo.cs (partial class)

    • Contents: GetClassInfo, CreateTestClassInfo, LoadType, CreateClassInfo, TryGetTimeoutInfo, UpdateInfoIfClassInitializeOrCleanupMethod, UpdateInfoIfTestInitializeOrCleanupMethod
    • Responsibility: Everything related to building and caching TestClassInfo
  3. TypeCache.AssemblyInfo.cs (partial class)

    • Contents: GetAssemblyInfo, CreateTestAssemblyInfo, UpdateInfoWithInitializeAndCleanupMethods, IsAssemblyOrClassInitializeMethod, IsAssemblyOrClassCleanupMethod
    • Responsibility: Everything related to building and caching TestAssemblyInfo
  4. TypeCache.ProviderDiscovery.cs (partial class)

    • Contents: DiscoverFixturesFromProviders, LoadProviderMarkers, ProcessProviderFixtureType, CollectFixtureMethodsFromProviderType, EnumerateCandidateAssemblies, TryLoadReferencedAssembly, HasAssemblyFixtureProviderMarker, IsFrameworkAssemblyName, SafeGetAssemblyName
    • Responsibility: Assembly fixture-provider scanning (the most self-contained chunk, ~250 lines)
  5. TypeCache.MethodResolution.cs (partial class)

    • Contents: ResolveTestMethodInfo, ResolveTestMethodInfoForDiscovery, GetMethodInfoForTestMethod, GetMethodInfoUsingManagedNameHelper
    • Responsibility: Resolving a TestMethod descriptor to a concrete MethodInfo

Implementation Guidelines

  1. Preserve Behavior: All existing functionality must work identically after the split
  2. Use partial classes: Declare internal sealed partial class TypeCache in every file — no new types, no renames
  3. One split at a time: Extract one partial file per commit to keep diffs reviewable
  4. Test after each split: Run ./build.sh -test (or .\build.cmd -test) after each step
  5. No public-API changes: TypeCache is internal, but keep all internal/public member signatures identical

Acceptance Criteria

  • Original file is split into focused partial-class files
  • Each new file is under 300 lines
  • All tests pass after refactoring (./build.sh -test)
  • No breaking changes to any public or internal API
  • File names follow the TypeCache.<Concern>.cs convention

Priority: Medium
Effort: Small — the class has no cross-cutting internal state between the proposed groups; splitting into partial files is low-risk
Expected Impact: Improved code navigability, easier testing of individual concerns, reduced merge conflicts

Generated by Daily File Diet · sonnet46 531.7K ·

  • expires on Jun 3, 2026, 8:20 PM UTC

Metadata

Metadata

Labels

type/automationCreated or maintained by an agentic workflow.type/tech-debtCode health, refactoring, simplification.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions