1 /* ****************************************************************************
3 * Copyright (c) Microsoft Corporation.
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.
11 * You must not remove this notice, or any other, from this software.
14 * ***************************************************************************/
19 using System.Collections.Generic;
20 using System.Diagnostics;
22 namespace Microsoft.Scripting.Utils {
24 public static class Assert {
26 public static Exception Unreachable {
28 Debug.Assert(false, "Unreachable");
29 return new InvalidOperationException("Code supposed to be unreachable");
33 [Conditional("DEBUG")]
34 public static void NotNull(object var) {
35 Debug.Assert(var != null);
38 [Conditional("DEBUG")]
39 public static void NotNull(object var1, object var2) {
40 Debug.Assert(var1 != null && var2 != null);
43 [Conditional("DEBUG")]
44 public static void NotNull(object var1, object var2, object var3) {
45 Debug.Assert(var1 != null && var2 != null && var3 != null);
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);
54 [Conditional("DEBUG")]
55 public static void NotEmpty(string str) {
56 Debug.Assert(!String.IsNullOrEmpty(str));
59 [Conditional("DEBUG")]
60 public static void NotEmpty<T>(ICollection<T> array) {
61 Debug.Assert(array != null && array.Count > 0);
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);
72 [Conditional("DEBUG")]
73 public static void IsTrue(Func<bool> predicate) {
74 ContractUtils.RequiresNotNull(predicate, "predicate");
75 Debug.Assert(predicate());