Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3119_AdditionalShapeConstraintFeatures/HeuristicLab.ExtLibs/HeuristicLab.ProtobufCS/2.4.1/ProtobufCS/src/ProtocolBuffers/ThrowHelper.cs

Last change on this file was 8295, checked in by abeham, 12 years ago

#1897:

  • Removed protocol buffers 0.9.1
  • Added protocol buffers 2.4.1
  • Updated proto processing command
File size: 3.4 KB
Line 
1#region Copyright notice and license
2
3// Protocol Buffers - Google's data interchange format
4// Copyright 2008 Google Inc.  All rights reserved.
5// http://github.com/jskeet/dotnet-protobufs/
6// Original C++/Java/Python code:
7// http://code.google.com/p/protobuf/
8//
9// Redistribution and use in source and binary forms, with or without
10// modification, are permitted provided that the following conditions are
11// met:
12//
13//     * Redistributions of source code must retain the above copyright
14// notice, this list of conditions and the following disclaimer.
15//     * Redistributions in binary form must reproduce the above
16// copyright notice, this list of conditions and the following disclaimer
17// in the documentation and/or other materials provided with the
18// distribution.
19//     * Neither the name of Google Inc. nor the names of its
20// contributors may be used to endorse or promote products derived from
21// this software without specific prior written permission.
22//
23// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
35#endregion
36
37using System;
38using System.Collections.Generic;
39
40namespace Google.ProtocolBuffers
41{
42    /// <summary>
43    /// Helper methods for throwing exceptions
44    /// </summary>
45    public static class ThrowHelper
46    {
47        /// <summary>
48        /// Throws an ArgumentNullException if the given value is null.
49        /// </summary>
50        public static void ThrowIfNull(object value, string name)
51        {
52            if (value == null)
53            {
54                throw new ArgumentNullException(name);
55            }
56        }
57
58        /// <summary>
59        /// Throws an ArgumentNullException if the given value is null.
60        /// </summary>
61        public static void ThrowIfNull(object value)
62        {
63            if (value == null)
64            {
65                throw new ArgumentNullException();
66            }
67        }
68
69        /// <summary>
70        /// Throws an ArgumentNullException if the given value or any element within it is null.
71        /// </summary>
72        public static void ThrowIfAnyNull<T>(IEnumerable<T> sequence)
73        {
74            foreach (T t in sequence)
75            {
76                if (t == null)
77                {
78                    throw new ArgumentNullException();
79                }
80            }
81        }
82
83        public static Exception CreateMissingMethod(Type type, string methodName)
84        {
85#if SILVERLIGHT
86            return new MissingMethodException(String.Format("The method '{0}' was not found on type {1}", methodName, type));
87#else
88            return new MissingMethodException(String.Format("{0}", type), methodName);
89#endif
90        }
91    }
92}
Note: See TracBrowser for help on using the repository browser.