sitecore Diagnostics: Asserts Argument Checks



This method checks to see if the argument specified is true. It also takes in the name of the argument that is logged if the condition fails.

Assert.ArgumentCondition(pageIndex >= 0, "pageIndex", "Value must be greater than or equal to zero.");


This method ensures that the argument passed is not null. There are two signatures for this method, the first takes in an object and a paramter name and does a simple null check.

Assert.ArgumentNotNull(item, "item");


This is similar to the ArgumentNotNull method, but will also check to see if the object is empty. There are three variants of this method. The first variant takes in a Sitecore ID and an argument name, and checks to see if the ID is null.

var nullId = new new ID("{00000000-0000-0000-0000-000000000000}");

// Both of these calls will result in an exception
Assert.ArgumentNotNullOrEmpty((ID)null, "null");
Assert.ArgumentNotNullOrEmpty(nullId, nameof(nullId));

The second method adds a check to see if the given string is null or empty.

// Both of these calls will result in an exception
Assert.ArgumentNotNullOrEmpty((string)null, "null");
Assert.ArgumentNotNullOrEmpty("", nameof(emptyString));