Stravaig.Extensions.Core

A set of small extensions to make life a little easier.

View on GitHub View on NuGet
Documentation last built on Thursday, 16 November, 2023

SEC0001: Use String HasContent()

Cause

The code contains a !string.IsNullOrWhiteSpace(aString) or string.IsNullOrWhiteSpace(aString) == false

Rule description

Replace !string.IsNullOrWhiteSpace(aString) or string.IsNullOrWhiteSpace(aString) == false with aString.HasContent() for readability.

How to fix violations

  1. Add a using declaration for the Stravaig.Extensions.Core namespace.
  2. Replace any instance of:
  3. !string.IsNullOrWhiteSpace(aString) with aString.HasContent()
  4. string.IsNullOrWhiteSpace(aString) == false with aString.HasContent()

When to suppress warnings

If you prefer the original style of string check.

Example of a violation


if (!string.IsNullOrWhiteSpace(aString))
{
    // Do something conditional on the string having some content.
}