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