Setters/adders now throw ArgumentNullException appropriately.
diff --git a/src/ProtocolBuffers/ThrowHelper.cs b/src/ProtocolBuffers/ThrowHelper.cs
new file mode 100644
index 0000000..2adede6
--- /dev/null
+++ b/src/ProtocolBuffers/ThrowHelper.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Google.ProtocolBuffers {
+ /// <summary>
+ /// Helper methods for throwing exceptions
+ /// </summary>
+ public static class ThrowHelper {
+
+ /// <summary>
+ /// Throws an ArgumentNullException if the given value is null.
+ /// </summary>
+ public static void ThrowIfNull(object value, string name) {
+ if (value == null) {
+ throw new ArgumentNullException(name);
+ }
+ }
+
+ /// <summary>
+ /// Throws an ArgumentNullException if the given value is null.
+ /// </summary>
+ public static void ThrowIfNull(object value) {
+ if (value == null) {
+ throw new ArgumentNullException();
+ }
+ }
+
+ /// <summary>
+ /// Throws an ArgumentNullException if the given value or any element within it is null.
+ /// </summary>
+ public static void ThrowIfAnyNull<T>(IEnumerable<T> sequence) {
+ foreach (T t in sequence) {
+ if (t == null) {
+ throw new ArgumentNullException();
+ }
+ }
+ }
+ }
+}