AssertExtensions.

ThrowIfNull<T>(T, string) Method

Summary

Throws a System.ArgumentNullException if the value is null, otherwise returns the value

Syntax

public static T ThrowIfNull<T>(this T value, string varName)

Examples

replace the following
if (myArg == null) 
{
  throw new ArgumentNullException(nameof(myArg));
}
var arg1 = myArg;
with
var arg1 = myArg.ThrowIfNull(nameof(myArg));

Attributes

Type Description
CakeAliasCategoryAttribute

Type Parameters

Name Description
T The type to return

Parameters

Name Type Description
value T The object to check
varName string The name of the variable

Return Value

Type Description
T The non-null value