Skip to content

Deduplicate ThrowTransientDisposableException across #if preprocessor branches #24

Description

@AGiorgetti

Description

ThrowTransientDisposableException in DetectIncorrectUsageOfTransientDisposables.cs has two nearly identical implementations (~30 lines each) split across #if NET8_0_OR_GREATER and #elif NETSTANDARD2_0_OR_GREATER preprocessor branches.

The only difference is the use of CultureInfo.InvariantCulture in string interpolation handlers (a .NET 8+ feature):

// NET8_0_OR_GREATER
sb.Append(CultureInfo.InvariantCulture, $"ServiceKey: {serviceKey}, ");

// NETSTANDARD2_0_OR_GREATER  
sb.Append($"ServiceKey: {serviceKey}, ");

Suggestion

Since netstandard2.0 supports CultureInfo.InvariantCulture, string.Format, and FormattableString.Invariant, consider unifying the two branches using FormattableString.Invariant() or string.Format(CultureInfo.InvariantCulture, ...) which works on all target frameworks. This eliminates ~30 lines of duplication.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions