rspec/rules/S3898/csharp/rule.adoc
2023-01-26 10:24:38 +01:00

29 lines
641 B
Plaintext

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
[source,csharp]
----
struct MyStruct // Noncompliant
{
public int Value { get; set; }
}
----
== Compliant Solution
[source,csharp]
----
struct MyStruct : IEquatable<MyStruct>
{
public int Value { get; set; }
public bool Equals(MyStruct other)
{
// ...
}
}
----
include::../see.adoc[]
include::../rspecator.adoc[]