rspec/rules/S2259/csharp/compliant-code.adoc
2023-07-03 17:26:15 +02:00

24 lines
570 B
Plaintext

Ensuring the variable `myObject` has a value resolves the issue:
[source,csharp,diff-id=1,diff-type=compliant]
----
public void Method()
{
var myObject = new object();
Console.WriteLine(myObject.ToString()); // Compliant: 'myObject' is not null
}
----
Preventing the non-compliant code to be executed by returning early:
[source,csharp,diff-id=2,diff-type=compliant]
----
public void Method(object input)
{
if (input is null)
{
return;
}
Console.WriteLine(input.ToString()); // Compliant: if 'input' is null, this is unreachable
}
----