You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1008 B
34 lines
1008 B
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Infrastructure.Domain
|
|
{
|
|
public abstract class BaseTreeEntity<T> : BaseEntity where T : BaseTreeEntity<T>
|
|
{
|
|
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<T> Children { get; set; } = new List<T>();
|
|
#pragma warning restore CA2227 // 集合属性应为只读
|
|
|
|
public List<T> GetPath()
|
|
{
|
|
var list = new List<T>();
|
|
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;
|
|
}
|
|
}
|
|
} |