rspec/rules/S3898/csharp/rule.adoc

50 lines
853 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
struct MyStruct // Noncompliant
{
private int i;
public int I
{
//...
}
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
struct MyStruct : IEquatable<MyStruct>
{
private int i;
public int I
{
//...
}
public bool Equals(MyStruct other)
{
throw new NotImplementedException();
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
endif::env-github,rspecator-view[]