In Sitecore you cannot compare an ID with NULL; it will produce the following error:
The call is ambiguous between the following methods or properties: ‘Sitecore.Data.ID.operator ==(Sitecore.Data.ID, Sitecore.Data.ID)’ and ‘Sitecore.Data.ID.operator ==(Sitecore.Data.ID, Sitecore.Data.ShortID)’
I.e. the following code is invalid:
Sitecore.Data.ID someID = GetSomeID(); if (someID == null) { // do code }
Instead, you need to call Sitecore.Data.ID.IsNullOrEmpty():
ID someID = GetSomeID(); if (Sitecore.Data.ID.IsNullOrEmpty(someID)) { // do code }
A quick tip for you.
You can remove the ambiguity if you wish like so as well:
if(myId == (ID)null) { … }
Though I suppose ID.IsNullOrEmpty() also checks for ID.Null.
LikeLike
Thx m8! Just what I neerded ;-)
LikeLike
Pingback: Which of my old Sitecore posts are still valid in Sitecore 9? | Brian Pedersen's Sitecore and .NET Blog