aboutsummaryrefslogtreecommitdiff
path: root/src/ProtocolBuffers/ThrowHelper.cs
blob: 2adede61eafc44672f773246191bc703655be621 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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();
        }
      }
    }
  }
}