private static IEnumerable <ProtocOutput> ProcessChildren(string[] data, int level, ref int index)
        {
            string prefix               = new string(' ', level * 2);
            string nextPrefix           = new string(' ', (level + 1) * 2);
            List <ProtocOutput> retVal  = new List <ProtocOutput>();
            ProtocOutput        preItem = null;

            while (index < data.Length)
            {
                if (data[index].StartsWith(nextPrefix))
                {
                    preItem.Children = ProcessChildren(data, level + 1, ref index);
                }
                else if (data[index].StartsWith(prefix))
                {
                    ProtocOutput item = new ProtocOutput {
                        ShowValue = data[index]
                    };
                    retVal.Add(item);
                    preItem = item;
                    index++;
                }
                else
                {
                    return(retVal);
                }
            }
            return(retVal);
        }
        private static IEnumerable <ProtocOutput> ProcessChildren(string[] data, int level, ProtocOutput parent, ref int index)
        {
            string prefix               = new string(' ', level * 2);
            string nextPrefix           = new string(' ', (level + 1) * 2);
            List <ProtocOutput> retVal  = new List <ProtocOutput>();
            ProtocOutput        preItem = null;

            while (index < data.Length)
            {
                if (data[index].StartsWith(nextPrefix))
                {
                    if (preItem != null)
                    {
                        ProcessChildren(data, level + 1, preItem, ref index);
                    }
                }
                else if (data[index].StartsWith(prefix))
                {
                    ProtocOutput item = new ProtocOutput {
                        Header = data[index]
                    };
                    if (parent == null)
                    {
                        retVal.Add(item);
                    }
                    else
                    {
                        parent.Items.Add(item);
                    }

                    preItem = item;
                    index++;
                }
                else
                {
                    return(retVal);
                }
            }
            return(retVal);
        }
Beispiel #3
0
 public void SetProtocOutput(string data)
 {
     treeView.ItemsSource = ProtocOutput.Parse(data);
 }