我正在开发一个 CAD 应用程序,其中有块实体。每个块实体都有一个子实体列表。When these entities are rendered, every block entity knows about its child entity (as it can figure out the child entity in the list), and hence when block entity is selected, the whole block entity along with its child entities gets selected. However, child entity does not know the parent block and other child entities of that block, and due to this when child entity is selected, I cannot get the whole block entity along with all its child entities selected.
为了解决这个问题,我在子实体中创建了一个属性来保存父块实体的引用。但是,交叉引用可能会出现一些问题,并使我的数据结构容易出错。
例如:有一个复制命令,几天后处理这些数据结构的人可能会在创建子实体的副本时复制同一个父实体。但是,新副本应该属于某个其他父块。
请提出实现这种关系的更好方法,以便在选择子实体时,我可以选择整个块实体及其所有子实体。
public class BlockEntity
{
public List<ChildEntity> Children = new List<ChildEntity>();
}
public class ChildEntity
{
public readonly BlockEntity Parent;
}