Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Ensures {
- public static Validation That {
- get { ... }
- }
- }
- public static class Requires {
- public static Validation That {
- get { ... }
- }
- }
- public static class Ensures {
- [ConditionalCallingCode("DEBUG")]
- public static Validation ThatDuringDebug {
- get { ... }
- }
- }
- public class Foo {
- public void Bar() {
- ... // do some work
- Ensures.That // do these checks always
- .IsNotNull(result)
- .IsInRange(result, 0, 100);
- Ensures.WhileDebuggingThat // only do these checks in debug mode
- .IsPositive(ExpensiveCalculation(result));
- return result;
- }
- }
- public class Foo {
- public void Bar() {
- ... // do some work
- Ensures.That // do these checks always
- .IsNotNull(result)
- .IsInRange(result, 0, 100);
- #ifdef DEBUG
- Ensures.That // only do these checks in debug mode
- .IsPositive(ExpensiveCalculation(result));
- #endif
- return result;
- }
- }
- using ValidationLibrary;
- public static class EnsuresWhileDebugging {
- [Conditional("DEBUG")]
- public static Validation That() {
- return Ensures.That;
- }
- }
- Ensures.That.IsPositive(ExpensiveCalculation(result));
- Ensures.WhileDebugging.That. IsPositive(() => ExpensiveCalculation(result));
- try
- {
- Debug.Assert(false);
- }
- catch (Exception e)
- {
- // will only and always run in debug mode
- }
- Debug.Assert(!Properties.Settings.Default.UseAutoDebug);
Add Comment
Please, Sign In to add comment