BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

chore: Replace `string.IsNullOrEmpty` method to IsBlank/IsNotBlank extension methods

Open filzrev opened this issue 3 weeks ago • 0 comments

This PR replace code that using string.IsNullOrEmpty method to use IsBlank/IsNotBlank extension methods.

Background

It's required to simplify code when enabled nullable features.

When targeting netstandard2.0 tfm. Nullable annotations are not set on string.IsNullOrEmpty

So following code needs extra ! annotation when targeting netstandard2.0.

string? value = null;
if (!string.IsNullOrEmpty(value))
{
    var length = value.Length!; // `!` is required
}

It can't change existing API's behaviors. So replace to existing extension methods (IsBlank/IsNotBlank)

Note: These extension methods using IsNullOrWhiteSpace instead of IsNullOrEmpty.

What's changed in this PR

  1. StringAndTextExtensions.cs / CommonExtensions.cs Add NotNullWhen attributes to existing IsBlank/IsNotBlank/IsNullOrEmpty extension methods.

  2. Other files Replace code that using string.IsNullOrEmpty to use IsBlank/IsNotBlank

filzrev avatar Dec 10 '25 03:12 filzrev