Paranoid

Namespace: SnowBank.Diagnostics.Contracts · class

Helper class present only in Paranoid mode, for checking pre-requisites, invariants, assertions, ...

Remarks

The methods of this class are only compiled if the PARANOID_ANDROID flag is defined

Properties

IsParanoid

static bool IsParanoid { get; }

Returns true at runtime if Paranoid checks are enforced

Things may get a lot slower!

Methods

Assert

static void Assert(bool condition, string userMessage = null, string conditionText = null)

[PARANOID ANDROID] Test if a condition is true, inside the body of a method.

  • condition — Condition that should never be false
  • userMessage — Message that describes the failed assertion (optional)
  • conditionText — Text of the condition (optional, injected by the compiler)

No-op if is true or if running a Release build. Otherwise, throws a ContractException, after attempting to breakpoint (if a debugger is attached).

Ensures

static void Ensures(bool condition, string userMessage = null, string conditionText = null)

[PARANOID ANDROID] Test if a post-condition is true, at the end of a method.

  • condition — Condition that should never be false
  • userMessage — Message that describes the failed assertion (optional)
  • conditionText — Text of the condition (optional, injected by the compiler)

No-op if is true or if running a Release build. Otherwise, throws a ContractException, after attempting to breakpoint (if a debugger is attached).

Invariant

static void Invariant(bool condition, string userMessage = null, string conditionText = null)

[DEBUG ONLY] Test that an invariant is met.

  • condition — Condition that should never be false
  • userMessage — Message that describes the failed assertion (optional)
  • conditionText — Text of the condition (optional, injected by the compiler)

No-op if is true or if running a Release build. Otherwise, throws a ContractException, after attempting to breakpoint (if a debugger is attached).

Requires

static void Requires(bool condition, string userMessage = null, string conditionText = null)

[PARANOID ANDROID] Test if a pre-condition is true, at the start of a method.

  • condition — Condition that should never be false
  • userMessage — Message that describes the failed assertion (optional)
  • conditionText — Text of the condition (optional, injected by the compiler)

No-op if is true or if running a Release build. Otherwise, throws a ContractException, after attempting to breakpoint (if a debugger is attached).