1 #region Copyright notice and license 2 // Protocol Buffers - Google's data interchange format 3 // Copyright 2008 Google Inc. All rights reserved. 4 // https://developers.google.com/protocol-buffers/ 5 // 6 // Redistribution and use in source and binary forms, with or without 7 // modification, are permitted provided that the following conditions are 8 // met: 9 // 10 // * Redistributions of source code must retain the above copyright 11 // notice, this list of conditions and the following disclaimer. 12 // * Redistributions in binary form must reproduce the above 13 // copyright notice, this list of conditions and the following disclaimer 14 // in the documentation and/or other materials provided with the 15 // distribution. 16 // * Neither the name of Google Inc. nor the names of its 17 // contributors may be used to endorse or promote products derived from 18 // this software without specific prior written permission. 19 // 20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 #endregion 32 33 namespace Google.Protobuf.WellKnownTypes 34 { 35 public partial class Value 36 { 37 /// <summary> 38 /// Convenience method to create a Value message with a string value. 39 /// </summary> 40 /// <param name="value">Value to set for the StringValue property.</param> 41 /// <returns>A newly-created Value message with the given value.</returns> ForString(string value)42 public static Value ForString(string value) 43 { 44 ProtoPreconditions.CheckNotNull(value, "value"); 45 return new Value { StringValue = value }; 46 } 47 48 /// <summary> 49 /// Convenience method to create a Value message with a number value. 50 /// </summary> 51 /// <param name="value">Value to set for the NumberValue property.</param> 52 /// <returns>A newly-created Value message with the given value.</returns> ForNumber(double value)53 public static Value ForNumber(double value) 54 { 55 return new Value { NumberValue = value }; 56 } 57 58 /// <summary> 59 /// Convenience method to create a Value message with a Boolean value. 60 /// </summary> 61 /// <param name="value">Value to set for the BoolValue property.</param> 62 /// <returns>A newly-created Value message with the given value.</returns> ForBool(bool value)63 public static Value ForBool(bool value) 64 { 65 return new Value { BoolValue = value }; 66 } 67 68 /// <summary> 69 /// Convenience method to create a Value message with a null initial value. 70 /// </summary> 71 /// <returns>A newly-created Value message a null initial value.</returns> ForNull()72 public static Value ForNull() 73 { 74 return new Value { NullValue = 0 }; 75 } 76 77 /// <summary> 78 /// Convenience method to create a Value message with an initial list of values. 79 /// </summary> 80 /// <remarks>The values provided are not cloned; the references are copied directly.</remarks> 81 /// <returns>A newly-created Value message an initial list value.</returns> ForList(params Value[] values)82 public static Value ForList(params Value[] values) 83 { 84 ProtoPreconditions.CheckNotNull(values, "values"); 85 return new Value { ListValue = new ListValue { Values = { values } } }; 86 } 87 88 /// <summary> 89 /// Convenience method to create a Value message with an initial struct value 90 /// </summary> 91 /// <remarks>The value provided is not cloned; the reference is copied directly.</remarks> 92 /// <returns>A newly-created Value message an initial struct value.</returns> ForStruct(Struct value)93 public static Value ForStruct(Struct value) 94 { 95 ProtoPreconditions.CheckNotNull(value, "value"); 96 return new Value { StructValue = value }; 97 } 98 } 99 } 100