🔍 Duplicate Code Detected: CommandLineProvider Boilerplate Structure
Analysis of commit 372c5f1
Summary
Detected significant structural duplication across ICommandLineOptionsProvider implementations for diagnostic extensions (HangDump, CrashDump). These providers share nearly identical boilerplate for property implementations, option registration, and validation patterns.
Duplication Details
Pattern: CommandLineProvider Structure
Impact Analysis
- Maintainability: Boilerplate property implementations repeated across providers
- Bug Risk: Validation logic patterns duplicated with minor variations
- Code Bloat: ~300+ lines of similar structural code
- Consistency: Difficult to ensure uniform validation behavior
Refactoring Recommendations
Option 1: Abstract Base Class (Recommended)
Create a base class that handles common provider patterns:
public abstract class ExtensionCommandLineProviderBase : ICommandLineOptionsProvider
{
private readonly IReadOnlyCollection<CommandLineOption> _cachedOptions;
protected ExtensionCommandLineProviderBase(IReadOnlyCollection<CommandLineOption> options)
{
_cachedOptions = options;
}
public abstract string Uid { get; }
public abstract string DisplayName { get; }
public abstract string Description { get; }
public virtual string Version => ExtensionVersion.DefaultSemVer;
public virtual Task<bool> IsEnabledAsync() => Task.FromResult(true);
public IReadOnlyCollection<CommandLineOption> GetCommandLineOptions() => _cachedOptions;
public virtual Task<ValidationResult> ValidateOptionArgumentsAsync(
CommandLineOption commandOption, string[] arguments)
=> ValidationResult.ValidTask;
public virtual Task<ValidationResult> ValidateCommandLineOptionsAsync(
ICommandLineOptions commandLineOptions)
=> ValidationResult.ValidTask;
}
// Usage:
internal sealed class HangDumpCommandLineProvider : ExtensionCommandLineProviderBase
{
private static readonly string[] HangDumpTypeOptions = ["Mini", "Heap", "Full", "Triage", "None"];
public HangDumpCommandLineProvider() : base(
[
new("hangdump", ExtensionResources.HangDumpOptionDescription, ArgumentArity.Zero, false),
new("hangdump-timeout", ExtensionResources.HangDumpTimeoutOptionDescription, ArgumentArity.ExactlyOne, false),
new("hangdump-filename", ExtensionResources.HangDumpFileNameOptionDescription, ArgumentArity.ExactlyOne, false),
new("hangdump-type", ExtensionResources.HangDumpTypeOptionDescription, ArgumentArity.ExactlyOne, false)
])
{
}
public override string Uid => nameof(HangDumpCommandLineProvider);
public override string DisplayName => ExtensionResources.HangDumpExtensionDisplayName;
public override string Description => ExtensionResources.HangDumpExtensionDescription;
public override Task<ValidationResult> ValidateOptionArgumentsAsync(
CommandLineOption commandOption, string[] arguments)
{
// Only validation-specific logic here
}
}
Benefits:
- Eliminates ~60% of boilerplate
- Centralizes common interface implementation
- Maintains type safety
- Easier to add new providers
Estimated effort: 4-6 hours
Option 2: Fluent Builder Pattern
Create a fluent builder for constructing command-line providers:
public class CommandLineProviderBuilder
{
public CommandLineProviderBuilder WithOption(string name, string description, ArgumentArity arity)
=> /* ... */;
public CommandLineProviderBuilder WithValidation(Func<CommandLineOption, string[], ValidationResult> validator)
=> /* ... */;
public ICommandLineOptionsProvider Build() => /* ... */;
}
Benefits:
- Declarative provider construction
- Reduces duplication
Drawbacks:
- Less discoverable
- More complex implementation
Estimated effort: 6-8 hours
Implementation Checklist
Analysis Metadata
- Analyzed Files: 895 C# source files
- Detection Method: Semantic code analysis + interface implementation pattern matching
- Commit: 372c5f1
- Analysis Date: 2026-05-25T05:45:53.799+00:00
- Pattern Type: Structural duplication (interface implementation boilerplate)
Generated by Duplicate Code Detector · ● 1.6M · ◷
Add this agentic workflows to your repo
To install this agentic workflow, run
gh aw add githubnext/agentics/workflows/duplicate-code-detector.md@main
🔍 Duplicate Code Detected: CommandLineProvider Boilerplate Structure
Analysis of commit 372c5f1
Summary
Detected significant structural duplication across
ICommandLineOptionsProviderimplementations for diagnostic extensions (HangDump, CrashDump). These providers share nearly identical boilerplate for property implementations, option registration, and validation patterns.Duplication Details
Pattern: CommandLineProvider Structure
Severity: Medium
Occurrences: 5+ instances
Locations:
src/Platform/Microsoft.Testing.Extensions.HangDump/HangDumpCommandLineProvider.cs(70 lines)src/Platform/Microsoft.Testing.Extensions.CrashDump/CrashDumpCommandLineProvider.cs(68 lines)src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/AzureDevOpsCommandLineProvider.cssrc/Platform/Microsoft.Testing.Extensions.MSBuild/MSBuildCommandLineProvider.cssrc/Platform/Microsoft.Testing.Platform/CommandLine/PlatformCommandLineProvider.csCode Sample (HangDump):
Code Sample (CrashDump - similar structure):
Impact Analysis
Refactoring Recommendations
Option 1: Abstract Base Class (Recommended)
Create a base class that handles common provider patterns:
Benefits:
Estimated effort: 4-6 hours
Option 2: Fluent Builder Pattern
Create a fluent builder for constructing command-line providers:
Benefits:
Drawbacks:
Estimated effort: 6-8 hours
Implementation Checklist
Analysis Metadata
Add this agentic workflows to your repo
To install this agentic workflow, run