/// <summary> /// Extended method for describing the node. It works more efficiently with strings /// and allows to describe a tree /// </summary> /// <param name="builder">Resulting string</param> /// <param name="node">Source node</param> /// <param name="level">Nesting level</param> public override void Describe(StringBuilder builder, Node node, int level) { if (node == null || builder == null) { return; } INodeDescriber describer = NodeDescriberFactory.GetDescriber(); Node firstChild = ((TwoChildrenNode)node).FirstChild; Node secondChild = ((TwoChildrenNode)node).SecondChild; this.AddIntent(builder, level); builder.Append($"new TwoChildrenNode(\"{node.Name}\""); if (firstChild != null) { builder.Append(",\n"); describer.Describe(builder, firstChild, level + 1); } if (secondChild != null) { builder.Append(",\n"); describer.Describe(builder, secondChild, level + 1); } builder.Append(")"); }
public static INodeDescriber GetNodeDescriber() { if (NodeDescriberimp == null) { NodeDescriberimp = new NodeDescriber(); } return(NodeDescriberimp); }
public Task WriteToFileAsync(Node node, string filePath) { return(Task.Factory.StartNew(() => { INodeDescriber describer = NodeDescriberFactory.GetDescriber(); string text = describer.Describe(node); using (StreamWriter w = new StreamWriter(filePath)) { w.Write(text); } })); }
/// <summary> /// Extended method for describing the node. It works more efficiently with strings /// and allows to describe a tree /// </summary> /// <param name="builder">Resulting string</param> /// <param name="node">Source node</param> /// <param name="level">Nesting level</param> public void Describe(StringBuilder builder, Node node, int level) { if (node == null || builder == null) { return; } INodeDescriber describer = nodeToDescriber[node.GetType()]; if (describer == null) { throw new Exception("There is no describer for the node"); } describer.Describe(builder, node, level); }
public NodeWriter(INodeDescriber nodeDescriber) { _nodeDescriber = nodeDescriber; }
public NodeWriter(INodeDescriber nodeDescriber) { this.nodeDescriber = nodeDescriber; }
public NodeWriter(INodeDescriber inodedes) { this.inodedes = inodedes; }
public NodeWriter (INodeDescriber nodeDescriber) { this._nodeDescriber = nodeDescriber; }