Hafner.Extensions.String.CheckNullOrEmpty 1.0.1

dotnet add package Hafner.Extensions.String.CheckNullOrEmpty --version 1.0.1
                    
NuGet\Install-Package Hafner.Extensions.String.CheckNullOrEmpty -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hafner.Extensions.String.CheckNullOrEmpty" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hafner.Extensions.String.CheckNullOrEmpty" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Hafner.Extensions.String.CheckNullOrEmpty" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Hafner.Extensions.String.CheckNullOrEmpty --version 1.0.1
                    
#r "nuget: Hafner.Extensions.String.CheckNullOrEmpty, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Hafner.Extensions.String.CheckNullOrEmpty@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Hafner.Extensions.String.CheckNullOrEmpty&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Hafner.Extensions.String.CheckNullOrEmpty&version=1.0.1
                    
Install as a Cake Tool

Hafner.Extensions.String.CheckNullOrEmpty

This micro package provides extension method System.String.CheckNullOrEmpty().

Description

Package Hafner.Extensions.String.CheckNullOrEmpty contains an extension method for a System.String that checks whether it is null (Nothing in Visual Basic) or empty and in case it is, throws an ArgumentNullException with a speaking message (using the automatically by the compiler filled in 2nd argument parameterName); otherwise, the object is returned.

This method is especially useful in conjunction with C#'s primary constructors where there is no built-in way to check the arguments before they are assigned.

public class Person(string firstName, string lastName) {

    public string FirstName { get; } = firstName.CheckNullOrEmpty();
    public string LastName { get; } = lastName.CheckNullOrEmpty();

}

Behavior and Edge Cases:

  • If the string is not null and not empty, the same instance is returned.
  • If the string is null or empty and the parameter name is null an ArgumentNullException with a generic message is thrown ("The argument is mandatory and cannot be null or empty!")
  • If the string is null or empty and the parameter name is recognized as an expression, an ArgumentNullException with an according message is thrown ("The result of the expression '{paramName}' is mandatory and cannot be null or empty!")
  • If the string is null or empty and the parameter name is recognized as a parameter name, an ArgumentNullException with an according message is thrown ("The argument for parameter '{paramName}' is mandatory and cannot be null or empty!")

Supported Frameworks:

  • .NET Framework versions 2.0, 3.0, 3.5, 4.0, 4.0.3, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
  • .NET Core versions 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0
  • .NET Standard versions 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp1.0 is compatible.  netcoreapp1.1 is compatible.  netcoreapp2.0 is compatible.  netcoreapp2.1 is compatible.  netcoreapp2.2 is compatible.  netcoreapp3.0 is compatible.  netcoreapp3.1 is compatible. 
.NET Standard netstandard1.0 is compatible.  netstandard1.1 is compatible.  netstandard1.2 is compatible.  netstandard1.3 is compatible.  netstandard1.4 is compatible.  netstandard1.5 is compatible.  netstandard1.6 is compatible.  netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net20 is compatible.  net30 is compatible.  net35 is compatible.  net40 is compatible.  net403 is compatible.  net45 is compatible.  net451 is compatible.  net452 is compatible.  net46 is compatible.  net461 is compatible.  net462 is compatible.  net463 was computed.  net47 is compatible.  net471 is compatible.  net472 is compatible.  net48 is compatible.  net481 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 was computed. 
Windows Phone wp8 was computed.  wp81 was computed.  wpa81 was computed. 
Windows Store netcore was computed.  netcore45 was computed.  netcore451 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 130 7/7/2025
1.0.0 126 7/6/2025

Package description adjusted.