Exemple #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(")");
        }
Exemple #2
0
 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);
        }
Exemple #5
0
 public NodeWriter(INodeDescriber nodeDescriber)
 {
     _nodeDescriber = nodeDescriber;
 }
Exemple #6
0
 public NodeWriter(INodeDescriber nodeDescriber)
 {
     this.nodeDescriber = nodeDescriber;
 }
Exemple #7
0
 public NodeWriter(INodeDescriber inodedes)
 {
     this.inodedes = inodedes;
 }
Exemple #8
0
 public NodeWriter (INodeDescriber nodeDescriber)
 {
     this._nodeDescriber = nodeDescriber;
 }