示例#1
0
        /// <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(")");
        }
示例#2
0
 public static INodeDescriber GetNodeDescriber()
 {
     if (NodeDescriberimp == null)
     {
         NodeDescriberimp = new NodeDescriber();
     }
     return(NodeDescriberimp);
 }
示例#3
0
        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);
        }
示例#5
0
 public NodeWriter(INodeDescriber nodeDescriber)
 {
     _nodeDescriber = nodeDescriber;
 }
示例#6
0
 public NodeWriter(INodeDescriber nodeDescriber)
 {
     this.nodeDescriber = nodeDescriber;
 }
示例#7
0
 public NodeWriter(INodeDescriber inodedes)
 {
     this.inodedes = inodedes;
 }
示例#8
0
 public NodeWriter (INodeDescriber nodeDescriber)
 {
     this._nodeDescriber = nodeDescriber;
 }