2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2023-03-14 15:55:28 +01:00
|
|
|
include::../description.adoc[]
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2023-03-14 15:55:28 +01:00
|
|
|
|
|
|
|
[source,vbnet]
|
|
|
|
----
|
|
|
|
Public Structure Coordinates
|
|
|
|
|
|
|
|
Public ReadOnly Property X As Integer
|
|
|
|
Public ReadOnly Property Y As Integer
|
|
|
|
|
|
|
|
<ExcludeFromCodeCoverage> ' Noncompliant
|
|
|
|
Public Overrides Function Equals(obj As Object) As Boolean
|
|
|
|
If Not (TypeOf obj Is Coordinates) Then
|
|
|
|
Return False
|
|
|
|
End If
|
|
|
|
|
|
|
|
Dim coordinates = DirectCast(obj, Coordinates)
|
|
|
|
Return X = coordinates.X AndAlso
|
|
|
|
Y = coordinates.Y
|
|
|
|
End Function
|
|
|
|
|
|
|
|
<ExcludeFromCodeCoverage> ' Noncompliant
|
|
|
|
Public Overrides Function GetHashCode() As Integer
|
|
|
|
Dim hashCode As Long = 1861411795
|
|
|
|
hashCode = (hashCode * -1521134295 + X.GetHashCode()).GetHashCode()
|
|
|
|
hashCode = (hashCode * -1521134295 + Y.GetHashCode()).GetHashCode()
|
|
|
|
Return hashCode
|
|
|
|
End Function
|
|
|
|
End Structure
|
|
|
|
----
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2023-03-14 15:55:28 +01:00
|
|
|
|
|
|
|
[source,vbnet]
|
|
|
|
----
|
|
|
|
Public Structure Coordinates
|
|
|
|
|
|
|
|
Public ReadOnly Property X As Integer
|
|
|
|
Public ReadOnly Property Y As Integer
|
|
|
|
|
|
|
|
<ExcludeFromCodeCoverage(Justification:="Code generated by Visual Studio refactoring")> ' Compliant
|
|
|
|
Public Overrides Function Equals(obj As Object) As Boolean
|
|
|
|
If Not (TypeOf obj Is Coordinates) Then
|
|
|
|
Return False
|
|
|
|
End If
|
|
|
|
|
|
|
|
Dim coordinates = DirectCast(obj, Coordinates)
|
|
|
|
Return X = coordinates.X AndAlso
|
|
|
|
Y = coordinates.Y
|
|
|
|
End Function
|
|
|
|
|
|
|
|
<ExcludeFromCodeCoverage(Justification:="Code generated by Visual Studio refactoring")> ' Compliant
|
|
|
|
Public Overrides Function GetHashCode() As Integer
|
|
|
|
Dim hashCode As Long = 1861411795
|
|
|
|
hashCode = (hashCode * -1521134295 + X.GetHashCode()).GetHashCode()
|
|
|
|
hashCode = (hashCode * -1521134295 + Y.GetHashCode()).GetHashCode()
|
|
|
|
Return hashCode
|
|
|
|
End Function
|
|
|
|
End Structure
|
|
|
|
----
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
include::../see.adoc[]
|