1 // -----------------------------------------------------------------------
\r
2 // Copyright (c) Microsoft Corporation. All rights reserved.
\r
3 // -----------------------------------------------------------------------
\r
5 using System.Collections;
\r
6 using System.Collections.Generic;
\r
7 using System.Diagnostics;
\r
9 using System.Globalization;
\r
10 using System.Reflection;
\r
11 using System.ComponentModel.Composition;
\r
14 namespace Microsoft.Internal
\r
16 internal static class Requires
\r
18 [DebuggerStepThrough]
\r
19 public static void NotNull<T>(T value, string parameterName)
\r
24 throw new ArgumentNullException(parameterName);
\r
28 [DebuggerStepThrough]
\r
29 public static void NotNullOrEmpty(string value, string parameterName)
\r
31 NotNull(value, parameterName);
\r
33 if (value.Length == 0)
\r
35 throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.ArgumentException_EmptyString, parameterName), parameterName);
\r
39 [DebuggerStepThrough]
\r
40 public static void NotNullOrNullElements<T>(IEnumerable<T> values, string parameterName)
\r
43 NotNull(values, parameterName);
\r
44 NotNullElements(values, parameterName);
\r
47 [DebuggerStepThrough]
\r
48 public static void NullOrNotNullElements<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> values, string parameterName)
\r
50 where TValue : class
\r
54 NotNullElements(values, parameterName);
\r
58 [DebuggerStepThrough]
\r
59 public static void NullOrNotNullElements<T>(IEnumerable<T> values, string parameterName)
\r
64 NotNullElements(values, parameterName);
\r
68 private static void NotNullElements<T>(IEnumerable<T> values, string parameterName)
\r
71 foreach (T value in values)
\r
75 throw ExceptionBuilder.CreateContainsNullElement(parameterName);
\r
80 private static void NotNullElements<TKey, TValue>(IEnumerable<KeyValuePair<TKey, TValue>> values, string parameterName)
\r
82 where TValue : class
\r
84 foreach (KeyValuePair<TKey, TValue> value in values)
\r
86 if ((value.Key == null) || (value.Value == null))
\r
88 throw ExceptionBuilder.CreateContainsNullElement(parameterName);
\r
92 [DebuggerStepThrough]
\r
93 public static void IsInMembertypeSet(MemberTypes value, string parameterName, MemberTypes enumFlagSet)
\r
95 if ((value & enumFlagSet) != value || // Ensure the member is in the set
\r
96 (value & (value - 1)) != 0) // Ensure that there is only one flag in the value (i.e. value is a power of 2).
\r
98 throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.ArgumentOutOfRange_InvalidEnumInSet, parameterName, value, enumFlagSet.ToString()), parameterName);
\r