コード例 #1
0
            public void PrintTree(ICommandInteraction writer, TreeViewBlock[] pattern = null)
            {
                if (pattern == null)
                {
                    pattern = new TreeViewBlock[0];
                }
                var indent = GetIndentString(pattern);

                writer.WriteLine(String.Format("{0}{1} ({2})", indent, PeripheralEntry.Name, PeripheralEntry.Type.Name));

                if (PeripheralEntry.Parent != null)
                {
                    var newIndent = GetIndentString(UpdatePattern(pattern, Children.Count > 0 ? TreeViewBlock.Straight : TreeViewBlock.Empty));
                    if (!(PeripheralEntry.RegistrationPoint is ITheOnlyPossibleRegistrationPoint))
                    {
                        foreach (var registerPlace in RegistrationPoints)
                        {
                            writer.WriteLine(String.Format("{0}{1}", newIndent, registerPlace.PrettyString));
                        }
                    }
                    writer.WriteLine(newIndent);
                }
                else
                {
                    writer.WriteLine(GetIndentString(new TreeViewBlock[] { TreeViewBlock.Straight }));
                }

                var lastChild = Children.LastOrDefault();

                foreach (var child in Children)
                {
                    child.PrintTree(writer, UpdatePattern(pattern, child != lastChild ? TreeViewBlock.Full : TreeViewBlock.End));
                }
            }
コード例 #2
0
            private static TreeViewBlock[] UpdatePattern(TreeViewBlock[] oldPattern, TreeViewBlock newSign)
            {
                FixLastSign(oldPattern);
                var newPattern = new TreeViewBlock[oldPattern.Length + 1];

                Array.Copy(oldPattern, newPattern, oldPattern.Length);
                newPattern[newPattern.Length - 1] = newSign;
                return(newPattern);
            }
コード例 #3
0
            private static String GetSingleIndentString(TreeViewBlock rawSignPattern)
            {
                switch (rawSignPattern)
                {
                case TreeViewBlock.Full:
                    return("├── ");

                case TreeViewBlock.End:
                    return("└── ");

                case TreeViewBlock.Straight:
                    return("│   ");

                case TreeViewBlock.Empty:
                    return("    ");

                default:
                    throw new ArgumentException();
                }
            }