Skip to content

CC0119: replace if statement by null coalescing operator (VB) #765

@kwhitefoot

Description

@kwhitefoot

New analyzer:

An if statement that tests an expression for null and assigns the value to a variable if not null and assigns some other value if the the expression is null can be replaced by the null coalescing operator

Before:

      If A IsNot Nothing Then
        C = A
      Else
        C = B
      End If

      If A IsNot Nothing Then
        Return A
      Else
        Return B
      End If


      If A Is Nothing Then
        C = B
      Else
        C = A
      End If

      If A Is Nothing Then
        Return B
      Else
        Return A
      End If

After:

      C = If(A, B)

      return If(A, B)

      C = If(A, B)

      return If(A, B)

Diagnostic Id: CC0119
Category: Style
Severity: Info

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions