rspec/rules/S2995/csharp/rule.adoc

45 lines
862 B
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Using ``++Object.ReferenceEquals++`` to compare the references of two value types simply won't return the expected results most of the time because such types are passed by value, not by reference.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
public class MyClass
{
private MyStruct myStruct;
public void DoSomething(MyStruct s1) {
int a = 1;
int b = 1;
if (Object.ReferenceEquals(myStruct, s1)) // Noncompliant; this can never be true
{
// ...
}
else if (Object.ReferenceEquals(a,b)) // Noncompliant
{
// ...
}
}
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]