private void DefaultVisit(CompareNode node) { foreach (var child in node.Children) { Visit(child); } }
/// <summary> /// Reduces a <see cref="CompareNode"/> to a new tree consisting of only the branches that contain differences.<para/> /// If every node in the specified tree has <see cref="TreeNodeDifference.None"/>, this method returns null. /// </summary> /// <param name="node">The root of the tree to reduce.</param> /// <returns>A tree with all branches consisting of <see cref="TreeNodeDifference.None"/> removed.</returns> public static CompareNode Reduce(this CompareNode node) { var reducer = new CompareNodeReducer(); var reduced = reducer.Visit(node); return(reduced); }
/// <summary> /// Pretty prints a <see cref="CompareNode"/> to a specified writer. /// </summary> /// <param name="node">The root of the tree to print.</param> /// <param name="writer">A writer that will be used for displaying the resulting text.</param> public static void PrettyPrint(this CompareNode node, PrettyWriter writer) { var visitor = new CompareNodePrettyTreeVisitor(); node.Accept(visitor); writer.Execute(visitor.Result); }
/// <summary> /// Retrieves all nodes that match a specified predicate from the descendants of a <see cref="CompareNode"/>. /// </summary> /// <param name="root">The node whose tree should be searched.</param> /// <param name="predicate">The condition to filter by.</param> /// <returns>A collection of nodes that matched the specified predicate.</returns> public static IEnumerable <CompareNode> FindNodes(this CompareNode root, Func <CompareNode, bool> predicate) { if (predicate == null) { predicate = v => true; } return(root?.DescendantNodes().Where(predicate)); }
/// <summary> /// Visits a single <see cref="CompareNode"/> and produces a value of type <typeparamref name="TResult"/>. /// </summary> /// <param name="node">The node to visit.</param> /// <returns>If the node was not null, the value produced by visiting it. Otherwise, the default value of <typeparamref name="TResult"/>.</returns> public virtual TResult Visit(CompareNode node) { if (node != null) { return(node.Accept(this)); } return(default(TResult)); }
/// <summary> /// The action to perform for all nodes whose visitor method is not overridden. /// </summary> /// <param name="node">The node to visit.</param> protected abstract void DefaultVisit(CompareNode node);
/// <summary> /// Visits a single <see cref="CompareNode"/>. /// </summary> /// <param name="node">The node to visit.</param> protected internal override void VisitNode(CompareNode node) => DefaultVisit(node);
/// <summary> /// Visits a single <see cref="TreeNodeType.Node"/> <see cref="CompareNode"/>. /// </summary> /// <param name="node">The node to visit.</param> protected internal abstract void VisitNode(CompareNode node);
public virtual void Visit(CompareNode node) => node.Accept(this);
public CompareNodeDebugView(CompareNode node) { this.node = node; }
/// <summary> /// Retrieves the single node that matches a specified predicate from the descendants of a <see cref="CompareNode"/>.<para/> /// If no matches are found, this method returns null. If multiple matches are found, an <see cref="InvalidOperationException"/> is thrown. /// </summary> /// <param name="root">The node whose tree should be searched.</param> /// <param name="predicate">The condition to filter by.</param> /// <exception cref="InvalidOperationException">Multiple nodes matched the specified predicate.</exception> /// <returns>If a single node matched the predicate, the node that matched the predicate. Otherwise, null.</returns> public static CompareNode FindNode(this CompareNode root, Func <CompareNode, bool> predicate) => FindNodes(root, predicate)?.SingleOrDefault();
/// <summary> /// Visits a single <see cref="TreeNodeType.Node"/> <see cref="CompareNode"/> and produces a value of type <typeparamref name="TResult"/>. /// </summary> /// <param name="node">The node to visit.</param> /// <returns>If the node was not null, the value produced by visiting it. Otherwise, the default value of <typeparamref name="TResult"/>.</returns> protected internal abstract TResult VisitNode(CompareNode node);
/// <summary> /// Initializes a new instance of the <see cref="CompareNodeRoot"/> class with the orphan this node encapsulates and the parent of this node. /// </summary> /// <param name="orphan">The orphan this node encapsulates.</param> /// <param name="parent">The parent of this node.</param> internal CompareNodeRoot(CompareOrphanRoot orphan, CompareNode parent) : base(orphan, parent) { }
/// <summary> /// Initializes a new instance of the <see cref="CompareNodeCollection"/> class with the orphan this node encapsulates and the parent of this node. /// </summary> /// <param name="orphan">The orphan this node encapsulates.</param> /// <param name="parent">The parent of this node.</param> internal CompareNodeCollection(CompareOrphanCollection orphan, CompareNode parent) : base(orphan, parent) { }