예제 #1
0
        void Load()
        {
            string[] lines;
            if (SourceText != null)
            {
                lines = SourceText.Lines().ToArray();
            }
            else
            {
                lines = File.ReadAllLines(SourceFilename);
            }
            Tree = new ModelNode();
            var currentNode = Tree;

            foreach (var line in lines)
            {
                var node = new ModelNode {
                    Text = line.Trim()
                };
                if (line.StartsWith("\t") || line.StartsWith(" "))
                {
                    currentNode.Add(node);
                }
                else
                {
                    Tree.Add(node);
                    currentNode = node;
                }
            }
            foreach (var ce in Tree.Nodes)
            {
                var ceTokens = ce.Text.Split(new string[] { " : " }, StringSplitOptions.None);
                ce.Name = ceTokens[0];
                if (ceTokens.Length > 1)
                {
                    ce.Type = ceTokens[1];
                }
                foreach (var pe in ce.Nodes)
                {
                    var peTokens = pe.Text.Split(new string[] { " " }, StringSplitOptions.None);
                    pe.Name = peTokens[1];
                    pe.Type = peTokens[0];
                }
            }
        }