-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseClass.cs
More file actions
95 lines (83 loc) · 2.51 KB
/
BaseClass.cs
File metadata and controls
95 lines (83 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections;
using System.Diagnostics;
namespace Scratch
{
public abstract class BaseClass
{
/// <summary>
/// Writes a blank line to the console.
/// </summary>
protected static void WL()
{
Console.WriteLine();
}
/// <summary>
/// Writes to the console.
/// </summary>
protected static void WL(object text, params object[] args)
{
var textStr = text?.ToString() ?? "<null>";
if (args == null || args.Length == 0)
{
Console.WriteLine(textStr);
}
else
{
Console.WriteLine(textStr, args);
}
}
/// <summary>
/// Writes an exception to the console.
/// </summary>
/// <remarks>
/// The full exception information will be output, including:
/// <list type="bullet">
/// <item><description>the type of the exception</description></item>
/// <item><description>the exception message</description></item>
/// <item><description>the exception stack trace</description></item>
/// <item><description>any <see cref="Exception.Data"/> information</description></item>
/// </list>
/// Inner exceptions will also have the above information output in full.
/// </remarks>
internal static void WE(Exception e)
{
WL();
WL(new string('-', 70));
WL(e.GetType());
WL(new string('-', 20));
WL(e.Message);
WL(new string('-', 20));
WL(e.StackTrace);
if (e.Data.Count > 0)
{
WL(new string('-', 20));
foreach (DictionaryEntry entry in e.Data)
{
WL(" {0}: {1}", entry.Key, entry.Value);
}
}
WL(new string('-', 70));
var baseException = e.GetBaseException();
if (baseException != e)
{
WE(baseException);
}
WL();
}
/// <summary>
/// Reads a line of text from the console.
/// </summary>
protected static string RL()
{
return Console.ReadLine();
}
/// <summary>
/// Signals a breakpoint to an attached debugger.
/// </summary>
protected static void Break()
{
Debugger.Break();
}
}
}