The Labs \ Source Viewer \ SSCLI \ System.Diagnostics \ Debug

  1. //------------------------------------------------------------------------------
  2. // <copyright file="Debug.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. /*
  16. */
  17. #define DEBUG
  18. namespace System.Diagnostics
  19. {
  20.     using System;
  21.     using System.Collections;
  22.     using System.Security.Permissions;
  23.     using System.Globalization;
  24.    
  25.     /// <devdoc>
  26.     /// <para>Provides a set of properties and
  27.     /// methods
  28.     /// for debugging code.</para>
  29.     /// </devdoc>
  30.     public sealed class Debug
  31.     {
  32.        
  33.         // not creatable...
  34.         //
  35.         private Debug()
  36.         {
  37.         }
  38.        
  39.         /// <devdoc>
  40.         /// <para>Gets
  41.         /// the collection of listeners that is monitoring the debug
  42.         /// output.</para>
  43.         /// </devdoc>
  44.         public static TraceListenerCollection Listeners {
  45.             [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
  46.             [HostProtection(SharedState = true)]
  47.             get { return TraceInternal.Listeners; }
  48.         }
  49.        
  50.         /// <devdoc>
  51.         /// <para>Gets or sets a value indicating whether <see cref='System.Diagnostics.Debug.Flush'/> should be called on the
  52.         /// <see cref='System.Diagnostics.Debug.Listeners'/>
  53.         /// after every write.</para>
  54.         /// </devdoc>
  55.         public static bool AutoFlush {
  56.             [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
  57.             get { return TraceInternal.AutoFlush; }
  58.            
  59.             [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
  60.             set { TraceInternal.AutoFlush = value; }
  61.         }
  62.        
  63.         /// <devdoc>
  64.         /// <para>Gets or sets
  65.         /// the indent level.</para>
  66.         /// </devdoc>
  67.         public static int IndentLevel {
  68.             get { return TraceInternal.IndentLevel; }
  69.            
  70.             set { TraceInternal.IndentLevel = value; }
  71.         }
  72.        
  73.         /// <devdoc>
  74.         /// <para>Gets or sets the number of spaces in an indent.</para>
  75.         /// </devdoc>
  76.         public static int IndentSize {
  77.             get { return TraceInternal.IndentSize; }
  78.            
  79.             set { TraceInternal.IndentSize = value; }
  80.         }
  81.        
  82.         /// <devdoc>
  83.         /// <para>Clears the output buffer, and causes buffered data to
  84.         /// be written to the <see cref='System.Diagnostics.Debug.Listeners'/>.</para>
  85.         /// </devdoc>
  86.         [System.Diagnostics.Conditional("DEBUG")]
  87.         public static void Flush()
  88.         {
  89.             TraceInternal.Flush();
  90.         }
  91.        
  92.         /// <devdoc>
  93.         /// <para>Clears the output buffer, and then closes the <see cref='System.Diagnostics.Debug.Listeners'/> so that they no longer receive
  94.         /// debugging output.</para>
  95.         /// </devdoc>
  96.         [System.Diagnostics.Conditional("DEBUG")]
  97.         [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
  98.         public static void Close()
  99.         {
  100.             TraceInternal.Close();
  101.         }
  102.        
  103.         /// <devdoc>
  104.         /// <para>Checks for a condition, and outputs the callstack if the condition is <see langword='false'/>.</para>
  105.         /// </devdoc>
  106.         [System.Diagnostics.Conditional("DEBUG")]
  107.         public static void Assert(bool condition)
  108.         {
  109.             TraceInternal.Assert(condition);
  110.         }
  111.        
  112.         /// <devdoc>
  113.         /// <para>Checks for a condition, and displays a message if the condition is
  114.         /// <see langword='false'/>. </para>
  115.         /// </devdoc>
  116.         [System.Diagnostics.Conditional("DEBUG")]
  117.         public static void Assert(bool condition, string message)
  118.         {
  119.             TraceInternal.Assert(condition, message);
  120.         }
  121.        
  122.         /// <devdoc>
  123.         /// <para>Checks for a condition, and displays both the specified messages if the condition
  124.         /// is <see langword='false'/>. </para>
  125.         /// </devdoc>
  126.         [System.Diagnostics.Conditional("DEBUG")]
  127.         public static void Assert(bool condition, string message, string detailMessage)
  128.         {
  129.             TraceInternal.Assert(condition, message, detailMessage);
  130.         }
  131.        
  132.         /// <devdoc>
  133.         /// <para>Emits or displays a message for an assertion that always fails.</para>
  134.         /// </devdoc>
  135.         [System.Diagnostics.Conditional("DEBUG")]
  136.         public static void Fail(string message)
  137.         {
  138.             TraceInternal.Fail(message);
  139.         }
  140.        
  141.         /// <devdoc>
  142.         /// <para>Emits or displays both messages for an assertion that always fails.</para>
  143.         /// </devdoc>
  144.         [System.Diagnostics.Conditional("DEBUG")]
  145.         public static void Fail(string message, string detailMessage)
  146.         {
  147.             TraceInternal.Fail(message, detailMessage);
  148.         }
  149.        
  150.         [System.Diagnostics.Conditional("DEBUG")]
  151.         public static void Print(string message)
  152.         {
  153.             TraceInternal.WriteLine(message);
  154.         }
  155.        
  156.         [System.Diagnostics.Conditional("DEBUG")]
  157.         public static void Print(string format, params object[] args)
  158.         {
  159.             TraceInternal.WriteLine(String.Format(CultureInfo.InvariantCulture, format, args));
  160.         }
  161.        
  162.         /// <devdoc>
  163.         /// <para>Writes a message to the trace listeners in the <see cref='System.Diagnostics.Debug.Listeners'/> collection.</para>
  164.         /// </devdoc>
  165.         [System.Diagnostics.Conditional("DEBUG")]
  166.         public static void Write(string message)
  167.         {
  168.             TraceInternal.Write(message);
  169.         }
  170.        
  171.         /// <devdoc>
  172.         /// <para>Writes the name of the value
  173.         /// parameter to the trace listeners in the <see cref='System.Diagnostics.Debug.Listeners'/> collection.</para>
  174.         /// </devdoc>
  175.         [System.Diagnostics.Conditional("DEBUG")]
  176.         public static void Write(object value)
  177.         {
  178.             TraceInternal.Write(value);
  179.         }
  180.        
  181.         /// <devdoc>
  182.         /// <para>Writes a category name and message
  183.         /// to the trace listeners in the <see cref='System.Diagnostics.Debug.Listeners'/> collection.</para>
  184.         /// </devdoc>
  185.         [System.Diagnostics.Conditional("DEBUG")]
  186.         public static void Write(string message, string category)
  187.         {
  188.             TraceInternal.Write(message, category);
  189.         }
  190.        
  191.         /// <devdoc>
  192.         /// <para>Writes a category name and the name of the value parameter to the trace
  193.         /// listeners in the <see cref='System.Diagnostics.Debug.Listeners'/> collection.</para>
  194.         /// </devdoc>
  195.         [System.Diagnostics.Conditional("DEBUG")]
  196.         public static void Write(object value, string category)
  197.         {
  198.             TraceInternal.Write(value, category);
  199.         }
  200.        
  201.         /// <devdoc>
  202.         /// <para>Writes a message followed by a line terminator to the trace listeners in the
  203.         /// <see cref='System.Diagnostics.Debug.Listeners'/> collection. The default line terminator
  204.         /// is a carriage return followed by a line feed (\r\n).</para>
  205.         /// </devdoc>
  206.         [System.Diagnostics.Conditional("DEBUG")]
  207.         public static void WriteLine(string message)
  208.         {
  209.             TraceInternal.WriteLine(message);
  210.         }
  211.        
  212.         /// <devdoc>
  213.         /// <para>Writes the name of the value
  214.         /// parameter followed by a line terminator to the
  215.         /// trace listeners in the <see cref='System.Diagnostics.Debug.Listeners'/> collection. The default line
  216.         /// terminator is a carriage return followed by a line feed (\r\n).</para>
  217.         /// </devdoc>
  218.         [System.Diagnostics.Conditional("DEBUG")]
  219.         public static void WriteLine(object value)
  220.         {
  221.             TraceInternal.WriteLine(value);
  222.         }
  223.        
  224.         /// <devdoc>
  225.         /// <para>Writes a category name and message followed by a line terminator to the trace
  226.         /// listeners in the <see cref='System.Diagnostics.Debug.Listeners'/> collection. The default line
  227.         /// terminator is a carriage return followed by a line feed (\r\n).</para>
  228.         /// </devdoc>
  229.         [System.Diagnostics.Conditional("DEBUG")]
  230.         public static void WriteLine(string message, string category)
  231.         {
  232.             TraceInternal.WriteLine(message, category);
  233.         }
  234.        
  235.         /// <devdoc>
  236.         /// <para>Writes a category name and the name of the value
  237.         /// parameter followed by a line
  238.         /// terminator to the trace listeners in the <see cref='System.Diagnostics.Debug.Listeners'/> collection. The
  239.         /// default line terminator is a carriage return followed by a line feed (\r\n).</para>
  240.         /// </devdoc>
  241.         [System.Diagnostics.Conditional("DEBUG")]
  242.         public static void WriteLine(object value, string category)
  243.         {
  244.             TraceInternal.WriteLine(value, category);
  245.         }
  246.        
  247.         /// <devdoc>
  248.         /// <para>Writes a message to the trace listeners in the <see cref='System.Diagnostics.Debug.Listeners'/> collection
  249.         /// if a condition is
  250.         /// <see langword='true'/>. </para>
  251.         /// </devdoc>
  252.         [System.Diagnostics.Conditional("DEBUG")]
  253.         public static void WriteIf(bool condition, string message)
  254.         {
  255.             TraceInternal.WriteIf(condition, message);
  256.         }
  257.        
  258.         /// <devdoc>
  259.         /// <para>Writes the name of the value
  260.         /// parameter to the trace listeners in the <see cref='System.Diagnostics.Debug.Listeners'/>
  261.         /// collection if a condition is
  262.         /// <see langword='true'/>. </para>
  263.         /// </devdoc>
  264.         [System.Diagnostics.Conditional("DEBUG")]
  265.         public static void WriteIf(bool condition, object value)
  266.         {
  267.             TraceInternal.WriteIf(condition, value);
  268.         }
  269.        
  270.         /// <devdoc>
  271.         /// <para>Writes a category name and message
  272.         /// to the trace listeners in the <see cref='System.Diagnostics.Debug.Listeners'/>
  273.         /// collection if a condition is
  274.         /// <see langword='true'/>. </para>
  275.         /// </devdoc>
  276.         [System.Diagnostics.Conditional("DEBUG")]
  277.         public static void WriteIf(bool condition, string message, string category)
  278.         {
  279.             TraceInternal.WriteIf(condition, message, category);
  280.         }
  281.        
  282.         /// <devdoc>
  283.         /// <para>Writes a category name and the name of the value
  284.         /// parameter to the trace
  285.         /// listeners in the <see cref='System.Diagnostics.Debug.Listeners'/> collection if a condition is
  286.         /// <see langword='true'/>. </para>
  287.         /// </devdoc>
  288.         [System.Diagnostics.Conditional("DEBUG")]
  289.         public static void WriteIf(bool condition, object value, string category)
  290.         {
  291.             TraceInternal.WriteIf(condition, value, category);
  292.         }
  293.        
  294.         /// <devdoc>
  295.         /// <para>Writes a message followed by a line terminator to the trace listeners in the
  296.         /// <see cref='System.Diagnostics.Debug.Listeners'/> collection if a condition is
  297.         /// <see langword='true'/>. The default line terminator is a carriage return followed
  298.         /// by a line feed (\r\n).</para>
  299.         /// </devdoc>
  300.         [System.Diagnostics.Conditional("DEBUG")]
  301.         public static void WriteLineIf(bool condition, string message)
  302.         {
  303.             TraceInternal.WriteLineIf(condition, message);
  304.         }
  305.        
  306.         /// <devdoc>
  307.         /// <para>Writes the name of the value
  308.         /// parameter followed by a line terminator to the
  309.         /// trace listeners in the <see cref='System.Diagnostics.Debug.Listeners'/> collection if a condition is
  310.         /// <see langword='true'/>. The default line terminator is a carriage return followed
  311.         /// by a line feed (\r\n).</para>
  312.         /// </devdoc>
  313.         [System.Diagnostics.Conditional("DEBUG")]
  314.         public static void WriteLineIf(bool condition, object value)
  315.         {
  316.             TraceInternal.WriteLineIf(condition, value);
  317.         }
  318.        
  319.         /// <devdoc>
  320.         /// <para>Writes a category name and message
  321.         /// followed by a line terminator to the trace
  322.         /// listeners in the <see cref='System.Diagnostics.Debug.Listeners'/> collection if a condition is
  323.         /// <see langword='true'/>. The default line terminator is a carriage return followed
  324.         /// by a line feed (\r\n).</para>
  325.         /// </devdoc>
  326.         [System.Diagnostics.Conditional("DEBUG")]
  327.         public static void WriteLineIf(bool condition, string message, string category)
  328.         {
  329.             TraceInternal.WriteLineIf(condition, message, category);
  330.         }
  331.        
  332.         /// <devdoc>
  333.         /// <para>Writes a category name and the name of the value parameter followed by a line
  334.         /// terminator to the trace listeners in the <see cref='System.Diagnostics.Debug.Listeners'/> collection
  335.         /// if a condition is <see langword='true'/>. The default line terminator is a carriage
  336.         /// return followed by a line feed (\r\n).</para>
  337.         /// </devdoc>
  338.         [System.Diagnostics.Conditional("DEBUG")]
  339.         public static void WriteLineIf(bool condition, object value, string category)
  340.         {
  341.             TraceInternal.WriteLineIf(condition, value, category);
  342.         }
  343.        
  344.         /// <devdoc>
  345.         /// <para>[To be supplied.]</para>
  346.         /// </devdoc>
  347.         [System.Diagnostics.Conditional("DEBUG")]
  348.         public static void Indent()
  349.         {
  350.             TraceInternal.Indent();
  351.         }
  352.        
  353.         /// <devdoc>
  354.         /// <para>[To be supplied.]</para>
  355.         /// </devdoc>
  356.         [System.Diagnostics.Conditional("DEBUG")]
  357.         public static void Unindent()
  358.         {
  359.             TraceInternal.Unindent();
  360.         }
  361.        
  362.     }
  363. }

Developer Fusion