Skip to content

[duplicate-code] Duplicate Code: Polyfill Attribute Decorator Pattern #8534

@Evangelink

Description

@Evangelink

🔍 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

  • Severity: Low-Medium

  • Occurrences: 49 attribute applications across 23 polyfill files

    • [ExcludeFromCodeCoverage]: 7 occurrences
    • [DebuggerNonUserCode]: 7 occurrences
    • [Embedded]: 35 occurrences
  • Locations: All files in src/Polyfills/

    • CallerArgumentExpressionAttribute.cs
    • ModuleInitializerAttribute.cs
    • RequiredMemberAttribute.cs
    • StackTraceHiddenAttribute.cs
    • ExperimentalAttribute.cs
    • InterpolatedStringHandlerAttribute.cs
    • InterpolatedStringHandlerArgumentAttribute.cs
    • ...and 16 more files
  • Code Sample:

// 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

  1. 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])
  2. 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
  3. 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
  4. 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

  • Review all 23 polyfill attribute files for decoration consistency
  • Research assembly/namespace-level attribute application feasibility
  • Choose refactoring approach based on technical constraints
  • Implement chosen solution (analyzer recommended for long-term)
  • Verify code coverage reports still exclude polyfills correctly
  • Ensure debugger behavior unchanged
  • Document polyfill decoration requirements
  • Add validation to prevent future inconsistencies

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
  • expires on May 26, 2026, 5:37 AM 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