diff options
author | mikebarnett <unknown> | 2011-03-10 17:37:58 +0000 |
---|---|---|
committer | mikebarnett <unknown> | 2011-03-10 17:37:58 +0000 |
commit | 768ee8abb31d912cfdc8eeaf41d7f44f1691ce0c (patch) | |
tree | 533ab6aa0d91c5a5e7c66125834fb5b8695ccf71 /Source/CodeContractsExtender | |
parent | e28c62b12194be07e3ecb3301e6b3e0336bcac2a (diff) |
Renamed NonNullElements to NonNullDictionaryAndValues because the keys to dictionaries are non-null, which is enforced by the implementation of Dictionary.
Added class constraints to all of the generic NonNull and NonNullElements methods so only non-value types will be checked.
Diffstat (limited to 'Source/CodeContractsExtender')
-rw-r--r-- | Source/CodeContractsExtender/cce.cs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/Source/CodeContractsExtender/cce.cs b/Source/CodeContractsExtender/cce.cs index 64b6527a..71462c07 100644 --- a/Source/CodeContractsExtender/cce.cs +++ b/Source/CodeContractsExtender/cce.cs @@ -15,18 +15,18 @@ public static class cce { // return collection != null && cce.NonNullElements(collection.TopologicallySortedComponents());
//}
[Pure]
- public static T NonNull<T>(T t) {
+ public static T NonNull<T>(T t) where T : class {
Contract.Requires(t != null);
Contract.Ensures(Contract.Result<T>() != null);
return t;
}
[Pure]
- public static bool NonNullElements<T>(IEnumerable<T> collection) {
+ public static bool NonNullElements<T>(IEnumerable<T> collection) where T : class {
return collection != null && Contract.ForAll(collection, c => c != null);
}
[Pure]
- public static bool NonNullElements<TKey, TValue>(IDictionary<TKey, TValue> collection) {
- return collection != null && Contract.ForAll(collection, pair => NonNullElements(pair));
+ public static bool NonNullDictionaryAndValues<TKey, TValue>(IDictionary<TKey, TValue> collection) where TValue : class {
+ return collection != null && cce.NonNullElements(collection.Values);
}
//[Pure]
//public static bool NonNullElements(VariableSeq collection) {
@@ -40,7 +40,7 @@ public static class cce { /// <param name="nullability">If true, the collection is treated as an IEnumerable<T!>?, rather than an IEnumerable<T!>!</param>
/// <returns></returns>
[Pure]
- public static bool NonNullElements<T>(IEnumerable<T> collection, bool nullability) {
+ public static bool NonNullElements<T>(IEnumerable<T> collection, bool nullability) where T : class {
return (nullability && collection == null) || cce.NonNullElements(collection);
//Should be the same as:
/*if(nullability&&collection==null)
@@ -50,11 +50,11 @@ public static class cce { }
[Pure]
- public static bool NonNullElements<TKey, TValue>(KeyValuePair<TKey, TValue> kvp) {
+ public static bool NonNullElements<TKey, TValue>(KeyValuePair<TKey, TValue> kvp) where TKey : class where TValue : class {
return kvp.Key != null && kvp.Value != null;
}
[Pure]
- public static bool NonNullElements<T>(IEnumerator<T> iEnumerator) {
+ public static bool NonNullElements<T>(IEnumerator<T> iEnumerator) where T : class {
return iEnumerator != null;
}
//[Pure]
@@ -135,6 +135,7 @@ public static class cce { //internal static bool NonNullElements(Set set) {
// return set != null && Contract.ForAll(0,set.Count, i => set[i] != null);
//}
+
}
public class PeerAttribute : SA {
|