Skip to main content

CRR0051 - String.IsNullOrEmpty can be used

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;
}

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;
}

Call the Use string.IsNullOrEmpty refactoring to replace the logical expression with the string.IsNullOrEmpty method call.