This analyzer detects logical expressions in which the null-check is performed after the value-check. Since boolean operators in C# and Visual Basic are short-circuit, the order of operands determines their execution order. Refer to the following code snippet.
If str.Length < 2 OrElse str Is Nothing Then ' CRR0017
In this example, an attempt to get the str.Length value will be made before checking that the str object is null (Nothing in VB). This will cause the System.NullReferenceException exception in case the str object is null (Nothing in VB). To avoid this, swap the operands so that the null-check is performed before any other checks. The execution will break as soon as one of the OR operands returns true.
If str Is Nothing OrElse str.Length < 2 Then
We are updating the DevExpress product documentation website and this page is part of our new experience. During this transition period, product documentation remains available in our previous format at documentation.devexpress.com. Learn More...
Was this page helpful?
Thanks for your feedback! Any other suggestions? Tell us here.