2
0

Debug.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. //
  2. // System.Diagnostics.Debug.cs
  3. //
  4. // Authors:
  5. // Jonathan Pryor ([email protected])
  6. //
  7. // Comments from John R. Hicks <[email protected]> original
  8. // implementation.
  9. //
  10. // (C) 2002
  11. //
  12. using System;
  13. using System.Diagnostics;
  14. namespace System.Diagnostics {
  15. /// <summary>
  16. /// Provides a set of methods to help debug code
  17. /// </summary>
  18. public sealed class Debug {
  19. /// <summary>
  20. /// Gets or sets value indicating whether Flush should
  21. /// be called on the listeners.
  22. /// </summary>
  23. public static bool AutoFlush {
  24. get {return TraceImpl.AutoFlush;}
  25. set {TraceImpl.AutoFlush = value;}
  26. }
  27. /// <summary>
  28. /// Gets or sets indent level
  29. /// </summary>
  30. public static int IndentLevel {
  31. get {return TraceImpl.IndentLevel;}
  32. set {TraceImpl.IndentLevel = value;}
  33. }
  34. /// <summary>
  35. /// The number of spaces in an indent.
  36. /// </summary>
  37. public static int IndentSize {
  38. get {return TraceImpl.IndentSize;}
  39. set {TraceImpl.IndentSize = value;}
  40. }
  41. /// <summary>
  42. /// Returns the listeners collection
  43. /// </summary>
  44. public static TraceListenerCollection Listeners {
  45. get {return TraceImpl.Listeners;}
  46. }
  47. /// <summary>
  48. /// Checks for a condition, and prints a stack trace
  49. /// if the condition is false.
  50. /// </summary>
  51. [Conditional("DEBUG")]
  52. public static void Assert (bool condition)
  53. {
  54. TraceImpl.Assert (condition);
  55. }
  56. /// <summary>
  57. /// Checks for a condition, and displays a message if the condition
  58. /// is false.
  59. /// </summary>
  60. [Conditional("DEBUG")]
  61. public static void Assert (bool condition, string message)
  62. {
  63. TraceImpl.Assert (condition, message);
  64. }
  65. /// <summary>
  66. /// Checks for a condtion, and displays a message and a detailed message
  67. /// string if the condition is false.
  68. /// </summary>
  69. [Conditional("DEBUG")]
  70. public static void Assert (bool condition, string message,
  71. string detailMessage)
  72. {
  73. TraceImpl.Assert (condition, message, detailMessage);
  74. }
  75. /// <summary>
  76. /// Closes the Debug buffer
  77. /// </summary>
  78. [Conditional("DEBUG")]
  79. public static void Close ()
  80. {
  81. TraceImpl.Close ();
  82. }
  83. /// <summary>
  84. /// Emits the specified error message.
  85. /// </summary>
  86. [Conditional("DEBUG")]
  87. public static void Fail (string message)
  88. {
  89. TraceImpl.Fail (message);
  90. }
  91. /// <summary>
  92. /// Emits the specified error message and detailed error message.
  93. /// </summary>
  94. [Conditional("DEBUG")]
  95. public static void Fail (string message, string detailMessage)
  96. {
  97. TraceImpl.Fail (message, detailMessage);
  98. }
  99. /// <summary>
  100. /// Flushes the listeners
  101. /// </summary>
  102. [Conditional("DEBUG")]
  103. public static void Flush ()
  104. {
  105. TraceImpl.Flush ();
  106. }
  107. /// <summary>
  108. /// Increments the indent level
  109. /// </summary>
  110. [Conditional("DEBUG")]
  111. public static void Indent ()
  112. {
  113. TraceImpl.Indent ();
  114. }
  115. /// <summary>
  116. /// Decrements the indent level
  117. /// </summary>
  118. [Conditional("DEBUG")]
  119. public static void Unindent ()
  120. {
  121. TraceImpl.Unindent ();
  122. }
  123. /// <summary>
  124. /// Writes the value of the specified object's ToString method
  125. /// to the listeners.
  126. /// </summary>
  127. [Conditional("DEBUG")]
  128. public static void Write (object value)
  129. {
  130. TraceImpl.Write (value);
  131. }
  132. /// <summary>
  133. /// Writes the specified message to each listener in the Listeners
  134. /// collection.
  135. /// </summary>
  136. [Conditional("DEBUG")]
  137. public static void Write (string message)
  138. {
  139. TraceImpl.Write (message);
  140. }
  141. /// <summary>
  142. /// Writes the category name and value of the specified object's
  143. /// ToString method to each listener in the Listeners collection.
  144. /// </summary>
  145. [Conditional("DEBUG")]
  146. public static void Write (object value, string category)
  147. {
  148. TraceImpl.Write (value, category);
  149. }
  150. /// <summary>
  151. /// Writes the category name and the specified message
  152. /// to each listener in the Listeners collection.
  153. /// </summary>
  154. [Conditional("DEBUG")]
  155. public static void Write (string message, string category)
  156. {
  157. TraceImpl.Write (message, category);
  158. }
  159. /// <summary>
  160. /// Writes the value of the specified object's ToString method
  161. /// to each of the listeners if the condition is true.
  162. /// </summary>
  163. [Conditional("DEBUG")]
  164. public static void WriteIf (bool condition, object value)
  165. {
  166. TraceImpl.WriteIf (condition, value);
  167. }
  168. /// <summary>
  169. /// Writes the specified message to each of the listeners
  170. /// if the specified condition is true.
  171. /// </summary>
  172. [Conditional("DEBUG")]
  173. public static void WriteIf (bool condition, string message)
  174. {
  175. TraceImpl.WriteIf (condition, message);
  176. }
  177. /// <summary>
  178. /// Writes the value of the specified object's ToString message
  179. /// and category to each of the listeners if the condition is true.
  180. /// </summary>
  181. [Conditional("DEBUG")]
  182. public static void WriteIf (bool condition, object value,
  183. string category)
  184. {
  185. TraceImpl.WriteIf (condition, value, category);
  186. }
  187. /// <summary>
  188. /// Writes the category and specified message to each listener
  189. /// if the specified condition is true.
  190. /// </summary>
  191. [Conditional("DEBUG")]
  192. public static void WriteIf (bool condition, string message,
  193. string category)
  194. {
  195. TraceImpl.WriteIf (condition, message, category);
  196. }
  197. /// <summary>
  198. /// Writes the value of the object's ToString method,
  199. /// followed by a line terminator, to each listener.
  200. /// </summary>
  201. [Conditional("DEBUG")]
  202. public static void WriteLine (object value)
  203. {
  204. TraceImpl.WriteLine (value);
  205. }
  206. /// <summary>
  207. /// Writes the specified message, followed by a line terminator,
  208. /// to each listener.
  209. /// </summary>
  210. [Conditional("DEBUG")]
  211. public static void WriteLine (string message)
  212. {
  213. TraceImpl.WriteLine (message);
  214. }
  215. /// <summary>
  216. /// Writes the value of the specified object's ToString method,
  217. /// along with a category, followed by a line terminator, to each listener.
  218. /// </summary>
  219. [Conditional("DEBUG")]
  220. public static void WriteLine (object value, string category)
  221. {
  222. TraceImpl.WriteLine (value, category);
  223. }
  224. /// <summary>
  225. /// Writes the specified category and message, followed by a line
  226. /// terminator, to each listener.
  227. /// </summary>
  228. [Conditional("DEBUG")]
  229. public static void WriteLine (string message, string category)
  230. {
  231. TraceImpl.WriteLine (message, category);
  232. }
  233. /// <summary>
  234. /// Writes the value of the object's ToString method
  235. /// to each listener if the specified condition is true.
  236. /// </summary>
  237. [Conditional("DEBUG")]
  238. public static void WriteLineIf (bool condition, object value)
  239. {
  240. TraceImpl.WriteLineIf (condition, value);
  241. }
  242. /// <summary>
  243. /// Writes the specified message to each listener
  244. /// if the specified condition is true.
  245. /// </summary>
  246. [Conditional("DEBUG")]
  247. public static void WriteLineIf (bool condition, string message)
  248. {
  249. TraceImpl.WriteLineIf (condition, message);
  250. }
  251. /// <summary>
  252. /// Writes the value of the object's ToString method, and a category
  253. /// to each listener if the specified condition is true.
  254. /// </summary>
  255. [Conditional("DEBUG")]
  256. public static void WriteLineIf (bool condition, object value,
  257. string category)
  258. {
  259. TraceImpl.WriteLineIf (condition, value, category);
  260. }
  261. /// <summary>
  262. /// Writes the specified category and message to each listener, followed
  263. /// by a line terminator, if the specified condition is true.
  264. /// </summary>
  265. [Conditional("DEBUG")]
  266. public static void WriteLineIf (bool condition, string message,
  267. string category)
  268. {
  269. TraceImpl.WriteLineIf (condition, message, category);
  270. }
  271. }
  272. }