Skip to content

Latest commit

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

"Buy Me A Coffee"

Extensions.IsNullOrEmpty

NuGet VersionNuGet DownloadsCIcodecovTwitter

Small set of C# extension methods to check for null/empty/zero across common types.

Install

Use the .NET CLI:

dotnet add package Kebechet.Extensions.IsNullOrEmpty

Usage

usingSystem;usingSystem.Collections.Generic;usingIsNullOrEmpty.Extensions;// Stringsstring?s1=null;boola=s1.IsNullOrEmpty();// truestring?s2=" ";boolb=s2.IsNullOrWhiteSpace();// true// CollectionsIEnumerable<int>?numbers=null;boolc=numbers.IsNullOrEmpty();// truevarlist=newList<string>();boold=list.IsNullOrEmpty();// true when empty// GuidGuid?id1=null;boole=id1.IsNullOrEmpty();// trueGuid?id2=Guid.Empty;boolf=id2.IsNullOrEmpty();// true// Numerics (nullable)int?i=0;long?l=null;double?dbl=0.0;decimal?dec=5m;float?fl=0f;boolg=i.IsNullOrZero();// trueboolh=l.IsNullOrZero();// trueboolj=dbl.IsNullOrZero();// trueboolk=dec.IsNullOrZero();// falseboolm=fl.IsNullOrZero();// true

Nullable flow analysis

All methods are annotated with [NotNullWhen(false)], so Roslyn's nullable analysis understands the null check:

string?name=GetName();if(name.IsNullOrEmpty()){return;}// No nullable warning here — Roslyn knows name is not nullConsole.WriteLine(name.Length);

API

  • string?:
    • IsNullOrEmpty()
    • IsNullOrWhiteSpace()
  • IEnumerable<T>?:
    • IsNullOrEmpty()
  • Guid?:
    • IsNullOrEmpty()
  • Numerics (sbyte?, byte?, short?, ushort?, int?, uint?, long?, ulong?, double?, decimal?, float?):
    • IsNullOrZero()

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages