|
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using QiHe.Yaml.Grammar;
namespace QiHe.Yaml.YamlUtility.UI
{
class YamlEmittor
{
public static TreeNode CreateNode(DataItem item)
{
if (item is Scalar)
{
return CreateNodeForScalar(item as Scalar);
}
else if (item is Sequence)
{
return CreateNodeForSequence(item as Sequence);
}
else if (item is Mapping)
{
return CreateNodeForMapping(item as Mapping);
}
else
{
return null;
}
}
private static TreeNode CreateNodeForScalar(Scalar scalar)
{
return new TreeNode(scalar.Text);
}
private static TreeNode CreateNodeForSequence(Sequence sequence)
{
TreeNode node = new TreeNode("Sequence");
foreach (DataItem item in sequence.Enties)
{
node.Nodes.Add(CreateNode(item));
}
return node;
}
private static TreeNode CreateNodeForMapping(Mapping mapping)
{
TreeNode node = new TreeNode("Mapping");
foreach (MappingEntry entry in mapping.Enties)
{
TreeNode nodeEntry = new TreeNode("Entry");
nodeEntry.Nodes.Add(CreateNode(entry.Key));
nodeEntry.Nodes.Add(CreateNode(entry.Value));
node.Nodes.Add(nodeEntry);
}
return node;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.