C# Class Zephyr.DesignByContract.Check

Design by Contract checks developed by http://www.codeproject.com/KB/cs/designbycontract.aspx. Each method generates an exception or a trace assertion statement if the contract is broken.
This example shows how to call the Require method. Assume DBC_CHECK_PRECONDITION is defined. public void Test(int x) { try { Check.Require(x > 1, "x must be > 1"); } catch (System.Exception ex) { Console.WriteLine(ex.ToString()); } } If you wish to use trace assertion statements, intended for Debug scenarios, rather than exception handling then set Check.UseAssertions = true You can specify this in your application entry point and maybe make it dependent on conditional compilation flags or configuration file settings, e.g., //#if DBC_USE_ASSERTIONS Check.UseAssertions = true; //#endif You can direct output to a Trace listener. For example, you could insert Trace.Listeners.Clear(); Trace.Listeners.Add(new TextWriterTraceListener(Console.Out)); or direct output to a file or the Event Log. (Note: For ASP.NET clients use the Listeners collection of the Debug, not the Trace, object and, for a Release build, only exception-handling is possible.)
Mostra file Open project: marufbd/Zephyr.NET

Private Properties

Property Type Description

Public Methods

Method Description
Assert ( bool assertion ) : void

Assertion check.

Assert ( bool assertion, string message ) : void

Assertion check.

Assert ( bool assertion, string message, Exception inner ) : void

Assertion check.

Ensure ( bool assertion ) : void

Postcondition check.

Ensure ( bool assertion, string message ) : void

Postcondition check.

Ensure ( bool assertion, string message, Exception inner ) : void

Postcondition check.

Invariant ( bool assertion ) : void

Invariant check.

Invariant ( bool assertion, string message ) : void

Invariant check.

Invariant ( bool assertion, string message, Exception inner ) : void

Invariant check.

Require ( bool assertion ) : void

Precondition check - should run regardless of preprocessor directives.

Require ( bool assertion, string message ) : void

Precondition check - should run regardless of preprocessor directives.

Require ( bool assertion, string message, Exception inner ) : void

Precondition check - should run regardless of preprocessor directives.

Method Details

Assert() public static method

Assertion check.
public static Assert ( bool assertion ) : void
assertion bool
return void

Assert() public static method

Assertion check.
public static Assert ( bool assertion, string message ) : void
assertion bool
message string
return void

Assert() public static method

Assertion check.
public static Assert ( bool assertion, string message, Exception inner ) : void
assertion bool
message string
inner System.Exception
return void

Ensure() public static method

Postcondition check.
public static Ensure ( bool assertion ) : void
assertion bool
return void

Ensure() public static method

Postcondition check.
public static Ensure ( bool assertion, string message ) : void
assertion bool
message string
return void

Ensure() public static method

Postcondition check.
public static Ensure ( bool assertion, string message, Exception inner ) : void
assertion bool
message string
inner System.Exception
return void

Invariant() public static method

Invariant check.
public static Invariant ( bool assertion ) : void
assertion bool
return void

Invariant() public static method

Invariant check.
public static Invariant ( bool assertion, string message ) : void
assertion bool
message string
return void

Invariant() public static method

Invariant check.
public static Invariant ( bool assertion, string message, Exception inner ) : void
assertion bool
message string
inner System.Exception
return void

Require() public static method

Precondition check - should run regardless of preprocessor directives.
public static Require ( bool assertion ) : void
assertion bool
return void

Require() public static method

Precondition check - should run regardless of preprocessor directives.
public static Require ( bool assertion, string message ) : void
assertion bool
message string
return void

Require() public static method

Precondition check - should run regardless of preprocessor directives.
public static Require ( bool assertion, string message, Exception inner ) : void
assertion bool
message string
inner System.Exception
return void