using System;
using System.Diagnostics;
using JetBrains.Annotations;
namespace Robust.Shared.Utility
{
public static class DebugTools
{
///
/// An assertion that will always an exception.
///
/// Exception message.
[Conditional("DEBUG")]
[ContractAnnotation("=> halt")]
public static void Assert(string message)
{
throw new DebugAssertException(message);
}
///
/// An assertion that will an exception if the
/// is not true.
///
/// Condition that must be true.
[Conditional("DEBUG")]
[AssertionMethod]
public static void Assert([AssertionCondition(AssertionConditionType.IS_TRUE)]
bool condition)
{
if (!condition)
throw new DebugAssertException();
}
///
/// An assertion that will an exception if the
/// is not true.
///
/// Condition that must be true.
/// Exception message.
[Conditional("DEBUG")]
[AssertionMethod]
public static void Assert([AssertionCondition(AssertionConditionType.IS_TRUE)]
bool condition, string message)
{
if (!condition)
throw new DebugAssertException(message);
}
///
/// An assertion that will an exception if the
/// is .
///
/// Condition that must be true.
[Conditional("DEBUG")]
[AssertionMethod]
public static void AssertNotNull([AssertionCondition(AssertionConditionType.IS_NOT_NULL)]
object? arg)
{
if (arg == null)
{
throw new DebugAssertException();
}
}
///
/// An assertion that will an exception if the
/// is not .
///
/// Condition that must be true.
[Conditional("DEBUG")]
[AssertionMethod]
public static void AssertNull([AssertionCondition(AssertionConditionType.IS_NULL)]
object? arg)
{
if (arg != null)
{
throw new DebugAssertException();
}
}
///
/// If a debugger is attached to the process, calling this function will cause the
/// debugger to break. Equivalent to a software interrupt (INT 3).
///
public static void Break()
{
Debugger.Break();
}
}
[Virtual]
public class DebugAssertException : Exception
{
public DebugAssertException()
{
}
public DebugAssertException(string message) : base(message)
{
}
}
}