diff options
author | Jon Skeet <jonskeet@google.com> | 2015-07-30 13:03:45 +0100 |
---|---|---|
committer | Jon Skeet <jonskeet@google.com> | 2015-07-30 13:36:45 +0100 |
commit | 68380f0f6681c72a5d4ab5e69abc9670e9d99838 (patch) | |
tree | f924bcd3a601cb55540924cc28fa7bbc600792cd /csharp/src/Google.Protobuf/Collections | |
parent | 7909b2edeb19affdf3f96a0b13a8098f28860c3c (diff) | |
download | protobuf-68380f0f6681c72a5d4ab5e69abc9670e9d99838.tar.gz protobuf-68380f0f6681c72a5d4ab5e69abc9670e9d99838.tar.bz2 protobuf-68380f0f6681c72a5d4ab5e69abc9670e9d99838.zip |
Rename ThrowHelper to Preconditions and make it public - we'll want to use it from the generated code soon.
Additionally, change it to return the value passed, and make it generic with a class constraint.
A separate method doesn't have the class constraint, for more unusual scenarios.
Diffstat (limited to 'csharp/src/Google.Protobuf/Collections')
-rw-r--r-- | csharp/src/Google.Protobuf/Collections/MapField.cs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/csharp/src/Google.Protobuf/Collections/MapField.cs b/csharp/src/Google.Protobuf/Collections/MapField.cs index 9f460e1e..fc94fd5c 100644 --- a/csharp/src/Google.Protobuf/Collections/MapField.cs +++ b/csharp/src/Google.Protobuf/Collections/MapField.cs @@ -112,13 +112,13 @@ namespace Google.Protobuf.Collections public bool ContainsKey(TKey key) { - ThrowHelper.ThrowIfNull(key, "key"); + Preconditions.CheckNotNullUnconstrained(key, "key"); return map.ContainsKey(key); } public bool Remove(TKey key) { - ThrowHelper.ThrowIfNull(key, "key"); + Preconditions.CheckNotNullUnconstrained(key, "key"); LinkedListNode<KeyValuePair<TKey, TValue>> node; if (map.TryGetValue(key, out node)) { @@ -151,7 +151,7 @@ namespace Google.Protobuf.Collections { get { - ThrowHelper.ThrowIfNull(key, "key"); + Preconditions.CheckNotNullUnconstrained(key, "key"); TValue value; if (TryGetValue(key, out value)) { @@ -161,11 +161,11 @@ namespace Google.Protobuf.Collections } set { - ThrowHelper.ThrowIfNull(key, "key"); + Preconditions.CheckNotNullUnconstrained(key, "key"); // value == null check here is redundant, but avoids boxing. if (value == null && !allowNullValues) { - ThrowHelper.ThrowIfNull(value, "value"); + Preconditions.CheckNotNullUnconstrained(value, "value"); } LinkedListNode<KeyValuePair<TKey, TValue>> node; var pair = new KeyValuePair<TKey, TValue>(key, value); @@ -187,7 +187,7 @@ namespace Google.Protobuf.Collections public void Add(IDictionary<TKey, TValue> entries) { - ThrowHelper.ThrowIfNull(entries, "entries"); + Preconditions.CheckNotNull(entries, "entries"); foreach (var pair in entries) { Add(pair.Key, pair.Value); @@ -374,7 +374,7 @@ namespace Google.Protobuf.Collections void IDictionary.Remove(object key) { - ThrowHelper.ThrowIfNull(key, "key"); + Preconditions.CheckNotNull(key, "key"); if (!(key is TKey)) { return; @@ -403,7 +403,7 @@ namespace Google.Protobuf.Collections { get { - ThrowHelper.ThrowIfNull(key, "key"); + Preconditions.CheckNotNull(key, "key"); if (!(key is TKey)) { return null; |