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.
Description
ThrowTransientDisposableExceptioninDetectIncorrectUsageOfTransientDisposables.cshas two nearly identical implementations (~30 lines each) split across#if NET8_0_OR_GREATERand#elif NETSTANDARD2_0_OR_GREATERpreprocessor branches.The only difference is the use of
CultureInfo.InvariantCulturein string interpolation handlers (a .NET 8+ feature):Suggestion
Since
netstandard2.0supportsCultureInfo.InvariantCulture,string.Format, andFormattableString.Invariant, consider unifying the two branches usingFormattableString.Invariant()orstring.Format(CultureInfo.InvariantCulture, ...)which works on all target frameworks. This eliminates ~30 lines of duplication.