Debug.cs 7.4 KB

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