using System; using System.Collections.Generic; namespace Infrastructure.Domain { public abstract class BaseTreeEntity : BaseEntity where T : BaseTreeEntity { public int DisplayOrder { get; set; } public int Left { get; set; } public int Right { get; set; } public Guid? ParentId { get; set; } public T Parent { get; set; } #pragma warning disable CA2227 // 集合属性应为只读 public List Children { get; set; } = new List(); #pragma warning restore CA2227 // 集合属性应为只读 public List GetPath() { var list = new List(); var item = this as T; while (item != null) { list.Add(item); if (item.Parent == null || item.Parent.Id == this.Id) { break; } item = item.Parent; } list.Reverse(); return list; } } }