Wednesday 16 October 2013

Checking null for Sitecore.Data.ID

The Sitecore.Data.ID class exposes a IsNull property which the documentation says it checks whether the instance is null. However I discovered that when the ID variable is actually null it throws Object reference set to null instance of object exception.

So it is better to the following code in this case (perhaps always?):
Sitecore.Data.ID.IsNullOrEmpty(myID)

No comments:

Post a Comment