Skip to content

Mutable Trees

David West edited this page Aug 29, 2016 · 24 revisions

< Error Detection

Creation

All mutable tree nodes share the MutableEntityTreeNode<TNode, TId, TItem> base class. To keep things moving for now, let's create our first mutable tree with the built-in concrete class MutableEntityTreeNode<TId, TItem>.

Construction and initial population of this tree will be identical to how it was shown in the section Creating Your First Entity Tree (with our source data tree coming from the section Up & Running).

var rootItem = new Category(dataRoot.Id, dataRoot.Name);

var root = new MutableEntityTreeNode<int, Category>(c => c.CategoryId, rootItem);

root.Build(dataRoot, dataNode => new Category(dataNode.Id, dataNode.Name);

Operations Overview

Here are all major operations that can be used to modify any tree composed of MutableEntityTreeNode<TNode, TId, TItem> elements. Signatures of the primary public members of this node type corresponding to these operations are shown:

####Add New Nodes >####

public virtual TNode AddChild(TItem item, int? insertIndex = null)
public virtual TNode AddAtAdjacentPosition(TItem item, Adjacency adjacency)

####Move Nodes >####

public virtual void MoveToParent(TId parentId, int? insertIndex = null)
public virtual void MoveToAdjacentPosition(TId targetId, Adjacency adjacency)
public virtual void IncrementSiblingPosition()
public virtual void DecrementSiblingPosition()

####Detach Nodes >####

public virtual void Detach()
public virtual void DetachWhere(Func<TNode, bool> satisfiesCondition)
public virtual void DetachChildren()

####Attach Nodes >####

public virtual void AttachChild(TNode node, int? insertionIndex = null)
public virtual void AttachAtAdjacentPosition(TNode node, Adjacency adjacency)

####Reorder Children >####

public virtual void OrderChildrenAscending<TOrderKey>(Func<TItem, TOrderKey> selectKey)
public virtual void OrderChildrenDescending<TOrderKey>(Func<TItem, TOrderKey> selectKey)
public virtual void OrderChildren(IComparer<TItem> itemComparer)
public virtual void OrderChildren(params TId[] preferredOrder)

Add New Nodes >

Clone this wiki locally