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

21 lines
582 B
Plaintext

Ensuring the variable `MyObject` has a value resolves the issue:
[source,vbnet,diff-id=1,diff-type=compliant]
----
Public Sub Method()
Dim MyObject As New Object
Console.WriteLine(MyObject.ToString) ' Compliant: 'MyObject' is not Nothing
End Sub
----
Preventing the non-compliant code to be executed by returning early:
[source,vbnet,diff-id=2,diff-type=compliant]
----
Public Sub Method(Input As Object)
If Input Is Nothing Then
Return
End If
Console.WriteLine(Input.ToString) ' Compliant: if 'Input' is Nothing, this part is unreachable
End Sub
----