blob: 2adede61eafc44672f773246191bc703655be621 [file] [log] [blame]
Jon Skeet642a8142009-01-27 12:25:21 +00001using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace Google.ProtocolBuffers {
6 /// <summary>
7 /// Helper methods for throwing exceptions
8 /// </summary>
9 public static class ThrowHelper {
10
11 /// <summary>
12 /// Throws an ArgumentNullException if the given value is null.
13 /// </summary>
14 public static void ThrowIfNull(object value, string name) {
15 if (value == null) {
16 throw new ArgumentNullException(name);
17 }
18 }
19
20 /// <summary>
21 /// Throws an ArgumentNullException if the given value is null.
22 /// </summary>
23 public static void ThrowIfNull(object value) {
24 if (value == null) {
25 throw new ArgumentNullException();
26 }
27 }
28
29 /// <summary>
30 /// Throws an ArgumentNullException if the given value or any element within it is null.
31 /// </summary>
32 public static void ThrowIfAnyNull<T>(IEnumerable<T> sequence) {
33 foreach (T t in sequence) {
34 if (t == null) {
35 throw new ArgumentNullException();
36 }
37 }
38 }
39 }
40}