HierarchyId
Methods
Method name
Return type
Description
Basic usage
// Create hierarchical id from ids of items in brunch of hierarchy
var hierarchyId = new HierarchyId(new int[] { 1, 2, 3, 4, 5 });
// Get string representation
var strId = hierarchyId.ToString(); // "/1/2/3/4/5/"
// Get current node id
var currentId = hierarchyId.GetNode(); // 5
// Check hierarchical relations
var f1 = hierarchyId.IsDescendantOf(3); // true
var f2 = hierarchyId.IsDescendantOf(6); // false
// Get ancestor
var a1 = hierarchyId.GetAncestor(1); // "/1/2/3/4/"
var a2 = hierarchyId.GetAncestor(3); // "/1/2/"
// Get hierarchical id for descendant of current node
var d = hierarchyId.GetDescendant(6); // "/1/2/3/4/5/6/"
// Get level of current node
var level = hierarchyId.GetLevel(); // 5
// Move current node to another brunch
var newHierarchyId = new HierarchyId(new int[] { 11, 12, 13, 14, 15 });
var ancestor1 = new HierarchyId(new int[] { 11, 12, 13 });
var ancestor2 = new HierarchyId(new int[] { 21, 22 });
newHierarchyId.Move(ancestor1, ancestor2); // results in "/21/22/14/15/"Last updated