10 static string EscapeString(
string s)
12 return s.Replace(
"\"",
"\\\"");
19 static void EscapeChar(
TextWriter output,
char c)
23 output.Write(
"'\\''");
28 output.Write(
"'{0}'", c);
34 output.Write(
"'\\a'");
38 output.Write(
"'\\b'");
42 output.Write(
"'\\n'");
46 output.Write(
"'\\v'");
50 output.Write(
"'\\r'");
54 output.Write(
"'\\f'");
62 output.Write(
"'\\x{0:x}", (int)c);
71 Print(output,
"null");
77 Array
a = (Array)result;
80 int top = a.GetUpperBound(0);
81 for (
int i = a.GetLowerBound(0); i <= top; i++)
83 PrettyPrint(output, a.GetValue(i));
89 else if (result is
bool)
92 Print(output,
"true");
94 Print(output,
"false");
96 else if (result is
string)
98 Print(output, String.Format(
"\"{0}\"", EscapeString((
string)result)));
100 else if (result is System.Collections.IDictionary)
102 var dict = (System.Collections.IDictionary)result;
103 int top = dict.Count,
count = 0;
106 foreach (System.Collections.DictionaryEntry entry in dict)
110 PrettyPrint(output, entry.Key);
112 PrettyPrint(output, entry.Value);
114 Print(output,
" }, ");
120 else if (result is System.Collections.IEnumerable)
124 foreach (
object item
in (System.Collections.IEnumerable)result)
129 PrettyPrint(output, item);
133 else if (result is
char)
135 EscapeChar(output, (
char)result);
139 Print(output, result.ToString());
static void PrettyPrint(TextWriter output, object result)