Is there a reason or something that I am missing that has Sitecore return true for both Item.Axes.IsDescendantOf() and Item.Axes.IsAncestorOf()?
var test =
Sitecore.Context.Database.GetItem("{862B466A-079B-40E7-8661-FC064EC28574}");
Response.Write(test.Axes.IsAncestorOf(test));
Response.Write(test.Axes.IsDes(test));
//True
//True
Edit: Anyone whom may stumble across this answer looking for non-inclusive IsAncestorOf or IsDescendantOf, below are a couple examples where I need to find the highest level elements in a multi-select field for news categories.
newsCategories
.Where(x => newsCategories
.Any(y => x != y && !x.Axes.IsDescendantOf(y)))
and
newsCategories
.Where(x => newsCategories
.Any(y => x != y && !x.Axes.IsDescendantOf(y)))
I would have to believe that the methods in Sitecore should not be named
IsAncestorOfandIsDescendantOf. Based on your finding, and quickly looking at the Sitecore code, the methods should really be namedIsAncestorOrSelfandIsDescendantOrSelf.For this example,
The
IsAncestorOfmethod is comparingx.ID == y.ID. It will then keep comparingx.IDto theIDof y’s parent, which is why it should be namedIsAncestorOrSelf.The
IsDescendantOfmethod is comparing if theLongIDpath ofxstarts with theLongIDpath ofy. Being that a string always starts with the same string we again see that this method should be namedIsDescendantOrSelf.FYI, A
LongIDpath looks like this/{11111111-1111-1111-1111-111111111111}/{0DE95AE4-41AB-4D01-9EB0-67441B7C2450}/{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}and I suspect is used rather than/sitecore/content/homein order to get around the fact that sitecore allows siblings to have the same name.