coderushforroslyn-115615-refactoring-assistance-use-string-is-null-or-empty.md
Converts an expression that checks whether a string is null or empty to the String.IsNullOrEmpty method call. This shortens the code and increases code performance.
Available when the cursor is within an expression checking whether a string is null or empty.
Place the caret on an expression against a string checking whether it is null or empty.
Press the Ctrl + . or Ctrl + ~ shortcut to invoke the Code Actions menu.
Select Use String.IsNullOrEmpty from the menu.
After execution, the Refactoring replaces the logical expression with the String.IsNullOrEmpty method call.
public bool AddRecord(string name, object data) {
if (String.IsNullOrEmpty(name) || data == null)
return false;
//...
return true;
}
Public Function AddRecord(ByVal name As String,
ByVal data As Object) As Boolean
If String.IsNullOrEmpty(name) OrElse
data Is Nothing Then
Return False
End If
'...
Return True
End Function
See Also