2009-07-11 Michael Barker <mike@middlesoft.co.uk>
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Dynamic / Assert.cs
1 /* ****************************************************************************
2  *
3  * Copyright (c) Microsoft Corporation. 
4  *
5  * This source code is subject to terms and conditions of the Microsoft Public License. A 
6  * copy of the license can be found in the License.html file at the root of this distribution. If 
7  * you cannot locate the  Microsoft Public License, please send an email to 
8  * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
9  * by the terms of the Microsoft Public License.
10  *
11  * You must not remove this notice, or any other, from this software.
12  *
13  *
14  * ***************************************************************************/
15
16 #define DEBUG
17 using System; using Microsoft;
18
19
20 using System.Collections.Generic;
21 using System.Diagnostics;
22
23 #if CODEPLEX_40
24 namespace System.Dynamic {
25 #else
26 namespace Microsoft.Scripting {
27 #endif
28     internal static class Assert {
29
30         internal static Exception Unreachable {
31             get {
32                 Debug.Assert(false, "Unreachable");
33                 return new InvalidOperationException("Code supposed to be unreachable");
34             }
35         }
36
37         [Conditional("DEBUG")]
38         internal static void NotNull(object var) {
39             Debug.Assert(var != null);
40         }
41
42         [Conditional("DEBUG")]
43         internal static void NotNull(object var1, object var2) {
44             Debug.Assert(var1 != null && var2 != null);
45         }
46
47         [Conditional("DEBUG")]
48         internal static void NotNull(object var1, object var2, object var3) {
49             Debug.Assert(var1 != null && var2 != null && var3 != null);
50         }
51
52         [Conditional("DEBUG")]
53         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1025:ReplaceRepetitiveArgumentsWithParamsArray")]
54         internal static void NotNull(object var1, object var2, object var3, object var4) {
55             Debug.Assert(var1 != null && var2 != null && var3 != null && var4 != null);
56         }
57
58         [Conditional("DEBUG")]
59         internal static void NotEmpty(string str) {
60             Debug.Assert(!String.IsNullOrEmpty(str));
61         }
62
63         [Conditional("DEBUG")]
64         internal static void NotEmpty<T>(ICollection<T> array) {
65             Debug.Assert(array != null && array.Count > 0);
66         }
67
68         [Conditional("DEBUG")]
69         internal static void NotNullItems<T>(IEnumerable<T> items) where T : class {
70             Debug.Assert(items != null);
71             foreach (object item in items) {
72                 Debug.Assert(item != null);
73             }
74         }
75
76         [Conditional("DEBUG")]
77         internal static void IsTrue(Func<bool> predicate) {
78             ContractUtils.RequiresNotNull(predicate, "predicate");
79             Debug.Assert(predicate());
80         }
81     }
82 }