|
| 1 | +// |
| 2 | +// Copyright (c) 2020 The nanoFramework project contributors |
| 3 | +// Portions Copyright (c) Microsoft Corporation. All rights reserved. |
| 4 | +// See LICENSE file in the project root for full license information. |
| 5 | +// |
| 6 | + |
| 7 | +using System.Runtime.CompilerServices; |
| 8 | + |
| 9 | +namespace System.Diagnostics |
| 10 | +{ |
| 11 | + /// <summary> |
| 12 | + /// Provides a set of methods and properties that help debug your code. |
| 13 | + /// </summary> |
| 14 | + public static class Debug |
| 15 | + { |
| 16 | + |
| 17 | + /// <summary> |
| 18 | + /// Causes a break in execution if the specified assertion (condition) evaluates to false. |
| 19 | + /// </summary> |
| 20 | + /// <param name="condition">The condition to be evaluated. If the value is false, program execution stops.</param> |
| 21 | + [Conditional("DEBUG")] |
| 22 | + static public void Assert(bool condition) |
| 23 | + { |
| 24 | + if (!condition) |
| 25 | + { |
| 26 | + Debugger.Break(); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + /// <summary> |
| 31 | + /// Causes a break in execution if the specified assertion (condition) evaluates to false. |
| 32 | + /// </summary> |
| 33 | + /// <param name="condition">The condition to be evaluated. If the value is false, program execution stops.</param> |
| 34 | + /// <param name="message">The text to be output if the assertion is false.</param> |
| 35 | + [Conditional("DEBUG")] |
| 36 | + static public void Assert(bool condition, string message) |
| 37 | + { |
| 38 | + if (!condition) |
| 39 | + { |
| 40 | + Debugger.Break(); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + /// <summary> |
| 45 | + /// Causes a break in execution if the specified assertion (condition) evaluates to false. |
| 46 | + /// </summary> |
| 47 | + /// <param name="condition">The condition to be evaluated. If the value is false, program execution stops.</param> |
| 48 | + /// <param name="message">The text to be output if the assertion is false.</param> |
| 49 | + /// <param name="detailedMessage">The detailed message to be displayed if the assertion is false.</param> |
| 50 | + [Conditional("DEBUG")] |
| 51 | + static public void Assert(bool condition, string message, string detailedMessage) |
| 52 | + { |
| 53 | + if (!condition) |
| 54 | + { |
| 55 | + Debugger.Break(); |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + /// <summary> |
| 60 | + /// Writes a message to the trace listeners in the Listeners collection. |
| 61 | + /// </summary> |
| 62 | + /// <param name="message">A message to write.</param> |
| 63 | + /// <remarks> |
| 64 | + /// In nanoFramework implementation the message is output to Visual Studio debugger window. |
| 65 | + /// </remarks> |
| 66 | + [Conditional("DEBUG")] |
| 67 | +#pragma warning disable S4200 // Native methods should be wrapped |
| 68 | + public static void Write(string message) => WriteLineNative(message, false); |
| 69 | +#pragma warning restore S4200 // Native methods should be wrapped |
| 70 | + |
| 71 | + /// <summary> |
| 72 | + /// Writes a message followed by a line terminator to the trace listeners in the Listeners collection. |
| 73 | + /// </summary> |
| 74 | + /// <param name="message">A message to write.</param> |
| 75 | + /// <remarks> |
| 76 | + /// In nanoFramework implementation the message is output to Visual Studio debugger window. |
| 77 | + /// </remarks> |
| 78 | + [Conditional("DEBUG")] |
| 79 | +#pragma warning disable S4200 // Native methods should be wrapped |
| 80 | + public static void WriteLine(string message) => WriteLineNative(message, true); |
| 81 | +#pragma warning restore S4200 // Native methods should be wrapped |
| 82 | + |
| 83 | + |
| 84 | + [MethodImpl(MethodImplOptions.InternalCall)] |
| 85 | + extern static private void WriteLineNative(string text, bool addLineFeed); |
| 86 | + } |
| 87 | +} |
0 commit comments