Instread of writing
if(parameter==null){thrownewArgumentNullException();}you can simply write
Guard.CannotBeNull(parameter);or using fluent syntax
parameter.CannotBeNull();You can optionally provide the parameter name or a custom error message (or both)
parameter.CannotBeNull("parameter","Custom Error Message");is the same as
if(parameter==null){thrownewArgumentNullException(paramName:"parameter",message:"Custom Error Message");}All clauses return the input parameter, so you can guard and consume it on the same line
this.SomeProperty=parameter.CannotBeNull();Nullable structs return non-nullable version
intnumber=input.MaybeNullNumber.CannotBeNull();Clauses are granular to provide maximum control of possible values
Ensure arrays and collections are not empty
items.CannotBeEmpty();//allows null but not emptyitems.CannotBeEmpty().CannotBeNull()//prevents bothEnsure strings are not empty ("") or blank (non-zero whitespace e.g. " ")
name.CannotBeEmpty().CannotBeBlank();Ensure guids are not empty (00000000-0000-0000-0000-000000000000)
id.CannotBeEmpty();