This analyzer identifies expressions that test a string for null (Nothing in Visual Basic) or an empty value, which can be replaced with a string.IsNullOrEmpty method call.
public bool AddRecord(string name, object data) {
if (name == null || name == string.Empty || data == null)
return false;
//...
return true;
}
Public Function AddRecord(ByVal name As String, ByVal data As Object) As Boolean
If name Is Nothing OrElse name = String.Empty OrElse data Is Nothing Then
Return False
End If
'...
Return True
End Function
To fix this issue, use the string.IsNullOrEmpty method call instead of logical expressions:
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
Call the Use string.IsNullOrEmpty refactoring to replace the logical expression with the string.IsNullOrEmpty method call.
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...