Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
DebugExtensions.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using System.Diagnostics.Contracts;
5 using System.Linq;
6 using System.Text;
7 
8 namespace SiliconStudio.Presentation.Quantum
9 {
10  public static class DebugExtensions
11  {
12  public static void AssertHierarchy(this IObservableNode node)
13  {
14  foreach (var child in node.Children)
15  {
16  if (child.Parent != node)
17  throw new Exception("Parent/Children mismatch");
18  AssertHierarchy(child);
19  }
20  }
21 
22  [Pure]
23  public static string PrintHierarchy(this IObservableNode node, int indentation = 0)
24  {
25  var builder = new StringBuilder();
26  PrintHierarchyInternal(node, 0, builder);
27  return builder.ToString();
28  }
29 
30  private static void PrintHierarchyInternal(IObservableNode node, int indentation, StringBuilder builder)
31  {
32  PrintIndentation(indentation, builder);
33  builder.Append(node.Name ?? "<untitled>");
34  if (node.Index != null)
35  {
36  builder.Append("[");
37  builder.Append(node.Index);
38  builder.Append("]");
39  }
40  builder.Append(": [");
41  builder.Append(node.Type.Name);
42  builder.Append("] = ");
43  builder.Append(node.Value == null ? "(null)" : node.Value.ToString().Replace(Environment.NewLine, " "));
44 
45  if (node.Commands.Any())
46  {
47  builder.Append("Cmd: ");
48  foreach (var command in node.Commands)
49  {
50  builder.Append("(");
51  builder.Append(((NodeCommandWrapperBase)command).Name);
52  builder.Append(")");
53  }
54  }
55  builder.AppendLine();
56  foreach (var child in node.Children)
57  {
58  PrintHierarchyInternal(child, indentation + 4, builder);
59  }
60  }
61 
62  private static void PrintIndentation(int indendation, StringBuilder builder)
63  {
64  for (int i = 0; i < indendation; ++i)
65  builder.Append(' ');
66  }
67 
68  }
69 }
IReadOnlyCollection< IObservableNode > Children
Gets the list of children nodes.
object Index
Gets or sets the index of this node, relative to its parent node when its contains a collection...
static void AssertHierarchy(this IObservableNode node)
IEnumerable< INodeCommandWrapper > Commands
Gets the list of commands available in this node.
static string PrintHierarchy(this IObservableNode node, int indentation=0)