Jon Skeet | 642a814 | 2009-01-27 12:25:21 +0000 | [diff] [blame] | 1 | using System; |
| 2 | using System.Collections.Generic; |
| 3 | using System.Text; |
| 4 | |
| 5 | namespace 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 | } |