🔍 Duplicate Code Detected: Polyfill Attribute Decorator Pattern
Analysis of commit 78e6371
Assignee: @copilot
Summary
The polyfill attributes in src/Polyfills/ (23 files) share repetitive decorator patterns applied 49 times across the codebase. The attributes [ExcludeFromCodeCoverage], [DebuggerNonUserCode], and [Embedded] are consistently applied to polyfill types, creating maintenance overhead when the decoration strategy needs to change.
Duplication Details
Pattern: Polyfill Attribute Decorators
// Pattern repeated across most polyfill files
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[AttributeUsage(AttributeTargets.Parameter)]
[Embedded]
internal sealed class CallerArgumentExpressionAttribute : Attribute
{
// ...
}
// Another example with the same decorators
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
[Embedded]
internal sealed class ModuleInitializerAttribute : Attribute;
// Yet another with identical decorators
[ExcludeFromCodeCoverage]
[DebuggerNonUserCode]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Embedded]
internal sealed class RequiredMemberAttribute : Attribute;
Impact Analysis
- Maintainability: If the decoration strategy changes (e.g., adding a new attribute or removing one), 23+ files need manual updates
- Bug Risk: Low - decorators are stable and unlikely to cause bugs, but inconsistent application could lead to coverage or debugging issues
- Code Bloat: ~50 redundant attribute declarations that follow the same pattern
- Consistency Risk: Manual decoration increases chance of forgetting to apply attributes to new polyfills
Refactoring Recommendations
-
Assembly-Level Attribute Application (If Possible)
- Investigate if
[assembly: ExcludeFromCodeCoverage] can be scoped to the Polyfills directory/namespace
- Use namespace-level attributes in a shared
PolyfillAttributes.cs file
- Estimated effort: 2-3 hours research + 1 hour implementation
- Benefits: Single source of truth for polyfill decoration strategy
- Drawbacks: May not work for all attribute types (especially
[Embedded])
-
Source Generator with Convention-Based Decoration
- Create analyzer/source generator that validates all polyfill types have required attributes
- Automatically apply decorators to types in
src/Polyfills/ directory
- Estimated effort: 6-8 hours
- Benefits: Compile-time enforcement, zero manual decoration
- Drawbacks: Increased build complexity
-
Code Review Checklist + Documentation
- Document the required decorators in
src/Polyfills/README.md
- Add analyzer rule to detect missing decorators on new polyfill types
- Create PR template checklist item for polyfill additions
- Estimated effort: 1-2 hours
- Benefits: Low implementation cost, clear guidance for contributors
- Drawbacks: Still requires manual application, relies on human review
-
Base Polyfill Attribute Class (Limited Applicability)
- Create abstract base class with the decorators applied once
- Inherit polyfill attributes from this base
- Estimated effort: 2-3 hours
- Benefits: Reduces duplication for new polyfills
- Drawbacks: Cannot apply to existing sealed attributes, changes inheritance hierarchy
Implementation Checklist
Analysis Metadata
- Analyzed Files: 23 polyfill attribute files in
src/Polyfills/
- Detection Method: Pattern counting with grep and attribute analysis
- Total Duplicate Decorators: 49 attribute applications
- Commit: 78e6371
- Analysis Date: 2026-05-24T05:30:57Z
Generated by Duplicate Code Detector · ● 1.4M · ◷
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: Polyfill Attribute Decorator Pattern
Analysis of commit 78e6371
Assignee:
@copilotSummary
The polyfill attributes in
src/Polyfills/(23 files) share repetitive decorator patterns applied 49 times across the codebase. The attributes[ExcludeFromCodeCoverage],[DebuggerNonUserCode], and[Embedded]are consistently applied to polyfill types, creating maintenance overhead when the decoration strategy needs to change.Duplication Details
Pattern: Polyfill Attribute Decorators
Severity: Low-Medium
Occurrences: 49 attribute applications across 23 polyfill files
[ExcludeFromCodeCoverage]: 7 occurrences[DebuggerNonUserCode]: 7 occurrences[Embedded]: 35 occurrencesLocations: All files in
src/Polyfills/CallerArgumentExpressionAttribute.csModuleInitializerAttribute.csRequiredMemberAttribute.csStackTraceHiddenAttribute.csExperimentalAttribute.csInterpolatedStringHandlerAttribute.csInterpolatedStringHandlerArgumentAttribute.csCode Sample:
Impact Analysis
Refactoring Recommendations
Assembly-Level Attribute Application (If Possible)
[assembly: ExcludeFromCodeCoverage]can be scoped to the Polyfills directory/namespacePolyfillAttributes.csfile[Embedded])Source Generator with Convention-Based Decoration
src/Polyfills/directoryCode Review Checklist + Documentation
src/Polyfills/README.mdBase Polyfill Attribute Class (Limited Applicability)
Implementation Checklist
Analysis Metadata
src/Polyfills/Add this agentic workflows to your repo
To install this agentic workflow, run