From 176eb454c86ebfa9301a4b978d37ae3e1e3fbfe5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20St=C3=BChmer?= Date: Thu, 29 Oct 2026 03:21:35 +0100 Subject: [PATCH] refactor: make ScopeHandler a sealed class to drop untestable equality members ScopeHandler was a readonly struct implementing IEquatable with Equals, GetHashCode and ==/!= operators that no test can reach, since Scope() and ScopeLine() only expose IDisposable. They showed up as NoCoverage mutants in Stryker. A private sealed class needs none of them. --- .../CSharpCodeBuilder.Scope.cs | 44 ++----------------- 1 file changed, 4 insertions(+), 40 deletions(-) diff --git a/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Scope.cs b/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Scope.cs index ae8a233c..7797acd1 100644 --- a/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Scope.cs +++ b/src/NetEvolve.CodeBuilder/CSharpCodeBuilder.Scope.cs @@ -50,18 +50,18 @@ public IDisposable ScopeLine(string? value) } /// - /// A disposable struct that manages indentation scope for a . + /// A disposable class that manages indentation scope for a . /// /// - /// This struct increments the indentation level when created and decrements it when disposed. + /// This class increments the indentation level when created and decrements it when disposed. /// It is designed to work with the 'using' statement to provide automatic indentation management. /// - private readonly struct ScopeHandler : IDisposable, IEquatable + private sealed class ScopeHandler : IDisposable { private readonly CSharpCodeBuilder _builder; /// - /// Initializes a new instance of the struct and increments the indentation level. + /// Initializes a new instance of the class and increments the indentation level. /// /// The instance to manage indentation for. internal ScopeHandler(CSharpCodeBuilder builder) @@ -77,41 +77,5 @@ internal ScopeHandler(CSharpCodeBuilder builder) /// This method is called automatically when the 'using' statement block ends. /// public void Dispose() => _ = _builder.Append('}'); - - /// - /// Determines whether the specified object is equal to the current instance. - /// - /// The object to compare with the current instance. - /// Always returns since ScopeHandler instances should not be compared. - public override readonly bool Equals(object? obj) => false; - - /// - /// Determines whether the specified ScopeHandler is equal to the current instance. - /// - /// The ScopeHandler to compare with the current instance. - /// Always returns since ScopeHandler instances should not be compared. - public readonly bool Equals(ScopeHandler other) => false; - - /// - /// Returns the hash code for this instance. - /// - /// A hash code based on the internal builder reference. - public override readonly int GetHashCode() => _builder?.GetHashCode() ?? 0; - - /// - /// Determines whether two ScopeHandler instances are equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// Always returns since ScopeHandler instances should not be compared. - public static bool operator ==(ScopeHandler _, ScopeHandler __) => false; - - /// - /// Determines whether two ScopeHandler instances are not equal. - /// - /// The first instance to compare. - /// The second instance to compare. - /// Always returns since ScopeHandler instances should not be compared. - public static bool operator !=(ScopeHandler _, ScopeHandler __) => true; } }