24 lines
570 B
Plaintext
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
|
||
|
}
|
||
|
----
|