Merge pull request #819 from brendanzagaeski/patch-1
[mono.git] / mcs / class / dlr / Runtime / Microsoft.Dynamic / Utils / Assert.cs
1 /* ****************************************************************************
2  *
3  * Copyright (c) Microsoft Corporation. 
4  *
5  * This source code is subject to terms and conditions of the Apache License, Version 2.0. 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  Apache License, Version 2.0, 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 Apache License, Version 2.0.
10  *
11  * You must not remove this notice, or any other, from this software.
12  *
13  *
14  * ***************************************************************************/
15
16 #define DEBUG
17
18 using System;
19 using System.Collections.Generic;
20 using System.Diagnostics;
21
22 namespace Microsoft.Scripting.Utils {
23
24     public static class Assert {
25
26         public static Exception Unreachable {
27             get {
28                 Debug.Assert(false, "Unreachable");
29                 return new InvalidOperationException("Code supposed to be unreachable");
30             }
31         }
32
33         [Conditional("DEBUG")]
34         public static void NotNull(object var) {
35             Debug.Assert(var != null);
36         }
37
38         [Conditional("DEBUG")]
39         public static void NotNull(object var1, object var2) {
40             Debug.Assert(var1 != null && var2 != null);
41         }
42
43         [Conditional("DEBUG")]
44         public static void NotNull(object var1, object var2, object var3) {
45             Debug.Assert(var1 != null && var2 != null && var3 != null);
46         }
47
48         [Conditional("DEBUG")]
49         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1025:ReplaceRepetitiveArgumentsWithParamsArray")]
50         public static void NotNull(object var1, object var2, object var3, object var4) {
51             Debug.Assert(var1 != null && var2 != null && var3 != null && var4 != null);
52         }
53
54         [Conditional("DEBUG")]
55         public static void NotEmpty(string str) {
56             Debug.Assert(!String.IsNullOrEmpty(str));
57         }
58
59         [Conditional("DEBUG")]
60         public static void NotEmpty<T>(ICollection<T> array) {
61             Debug.Assert(array != null && array.Count > 0);
62         }
63
64         [Conditional("DEBUG")]
65         public static void NotNullItems<T>(IEnumerable<T> items) where T : class {
66             Debug.Assert(items != null);
67             foreach (object item in items) {
68                 Debug.Assert(item != null);
69             }
70         }
71
72         [Conditional("DEBUG")]
73         public static void IsTrue(Func<bool> predicate) {
74             ContractUtils.RequiresNotNull(predicate, "predicate");
75             Debug.Assert(predicate());
76         }
77     }
78 }