Path: redb/redb.Core/Models/Contracts/ITreeNode.cs Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Models/Contracts/ITreeNode.cs ---- using System; using System.Collections.Generic; using System.Linq; namespace redb.Core.Models.Contracts { /// /// Interface for tree nodes with navigational properties and traversal operations /// /// Tree node type public interface ITreeNode where T : class, ITreeNode { /// /// Unique node identifier /// long Id { get; set; } /// /// Parent node identifier (null for root nodes) /// long? ParentId { get; set; } /// /// Reference to parent node (filled when loading tree) /// T? Parent { get; set; } /// /// Collection of child nodes (filled when loading tree) /// ICollection Children { get; set; } /// /// Checks if node is root (has no parent) /// bool IsRoot => ParentId == null; /// /// Checks if node is leaf (has no children) /// bool IsLeaf => !Children.Any(); /// /// Gets node level in tree (0 for root) /// Requires loaded hierarchy up to root /// int Level { get { int level = 0; var current = Parent; while (current != null) { level++; current = current.Parent; } return level; } } /// /// Gets all node ancestors (from parent to root) /// Requires loaded hierarchy up to root /// IEnumerable Ancestors { get { var current = Parent; while (current != null) { yield return current; current = current.Parent; } } } /// /// Gets all node descendants recursively /// Requires loaded hierarchy downwards /// IEnumerable Descendants { get { foreach (var child in Children) { yield return child; foreach (var descendant in child.Descendants) yield return descendant; } } } } }