AssertExtensions.

ThrowIfNull<T>(T, string, string) Method

Summary

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

Syntax

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

Examples

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

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
message string The exception message

Return Value

Type Description
T The non-null value