sonar-dotnet icon indicating copy to clipboard operation
sonar-dotnet copied to clipboard

Implement S3898 -ValueTypes should implement IEquatable - for VB.NET

Open Corniel opened this issue 3 years ago • 0 comments

See RSPEC 3898

Description

If you’re using a struct, it is likely because you’re interested in performance. But by failing to implement IEquatable<T> you’re loosing performance when comparisons are made because without IEquatable<T>, boxing and reflection are used to make comparisons.

Noncompliant Code Example

Structure MyStruct ' Noncompliant
    ' ...
End Structure

Compliant Solution

Structure MyStruct
    Implements IEquatable(Of MyStruct)
    
	 Public Overloads Function Equals(other As MyStruct) As Boolean Implements IEquatable(Of MyStruct).Equals
         ' ...
     End Function
	
	' ...
	
End Structure

Corniel avatar Jun 14 '22 09:06 Corniel