|
6 | 6 | */
|
7 | 7 | using System;
|
8 | 8 | using System.Collections.Generic;
|
| 9 | +using System.Reflection; |
9 | 10 | using System.Text;
|
10 | 11 | using UnityEngine;
|
| 12 | +using System.Collections; |
11 | 13 |
|
12 | 14 | namespace Beats2
|
13 | 15 | {
|
@@ -84,7 +86,35 @@ public static string GetLogHistoryString()
|
84 | 86 | }
|
85 | 87 | return logHistory.ToString();
|
86 | 88 | }
|
87 |
| - |
| 89 | + |
| 90 | + public static string DumpFields(object obj, int indentCount = 0) |
| 91 | + { |
| 92 | + string indent = new string('\t', indentCount); |
| 93 | + string indentInner = new string('\t', indentCount + 1); |
| 94 | + StringBuilder properties = new StringBuilder(); |
| 95 | + |
| 96 | + properties.AppendLine(indent + "{"); |
| 97 | + |
| 98 | + // Use reflection to get list of properties and their values |
| 99 | + Type type = obj.GetType(); |
| 100 | + foreach (FieldInfo field in type.GetFields()) { |
| 101 | + string name = field.Name; |
| 102 | + object value = field.GetValue(obj); |
| 103 | + if (value is ICollection) { |
| 104 | + // Recursively print inner objects |
| 105 | + properties.AppendLine(string.Format("{0}{1} =", indentInner, name)); |
| 106 | + foreach (ICollection item in ((ICollection)value)) { |
| 107 | + properties.AppendLine(DumpFields(item, indentCount + 1)); |
| 108 | + } |
| 109 | + } else { |
| 110 | + properties.AppendLine(string.Format("{0}{1} = {2}", indentInner, name, value)); |
| 111 | + } |
| 112 | + } |
| 113 | + properties.AppendLine(indent + "}"); |
| 114 | + |
| 115 | + return properties.ToString(); |
| 116 | + } |
| 117 | + |
88 | 118 | private static string FormatLogString(string type, string tag, string format, params object[] args)
|
89 | 119 | {
|
90 | 120 | return String.Format("{0}|{1}: {2}", type, tag, String.Format(format, args));
|
|
0 commit comments