aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/src/Google.Protobuf
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/Google.Protobuf')
-rw-r--r--csharp/src/Google.Protobuf/Reflection/CustomOptions.cs390
-rw-r--r--csharp/src/Google.Protobuf/Reflection/Descriptor.cs32
-rw-r--r--csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs5
-rw-r--r--csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs5
-rw-r--r--csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs5
-rw-r--r--csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs5
-rw-r--r--csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs5
-rw-r--r--csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs5
-rw-r--r--csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs5
-rw-r--r--csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs5
10 files changed, 454 insertions, 8 deletions
diff --git a/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs b/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs
new file mode 100644
index 00000000..88b3ec00
--- /dev/null
+++ b/csharp/src/Google.Protobuf/Reflection/CustomOptions.cs
@@ -0,0 +1,390 @@
+#region Copyright notice and license
+// Protocol Buffers - Google's data interchange format
+// Copyright 2017 Google Inc. All rights reserved.
+// https://developers.google.com/protocol-buffers/
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following disclaimer
+// in the documentation and/or other materials provided with the
+// distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#endregion
+
+using System;
+using System.Collections.Generic;
+
+namespace Google.Protobuf.Reflection
+{
+ /// <summary>
+ /// Container for a set of custom options specified within a message, field etc.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// This type is publicly immutable, but internally mutable. It is only populated
+ /// by the descriptor parsing code - by the time any user code is able to see an instance,
+ /// it will be fully initialized.
+ /// </para>
+ /// <para>
+ /// If an option is requested using the incorrect method, an answer may still be returned: all
+ /// of the numeric types are represented internally using 64-bit integers, for example. It is up to
+ /// the caller to ensure that they make the appropriate method call for the option they're interested in.
+ /// Note that enum options are simply stored as integers, so the value should be fetched using
+ /// <see cref="TryGetInt32(int, out int)"/> and then cast appropriately.
+ /// </para>
+ /// <para>
+ /// Repeated options are currently not supported. Asking for a single value of an option
+ /// which was actually repeated will return the last value, except for message types where
+ /// all the set values are merged together.
+ /// </para>
+ /// </remarks>
+ public sealed class CustomOptions
+ {
+ /// <summary>
+ /// Singleton for all descriptors with an empty set of options.
+ /// </summary>
+ internal static readonly CustomOptions Empty = new CustomOptions();
+
+ /// <summary>
+ /// A sequence of values per field. This needs to be per field rather than per tag to allow correct deserialization
+ /// of repeated fields which could be "int, ByteString, int" - unlikely as that is. The fact that values are boxed
+ /// is unfortunate; we might be able to use a struct instead, and we could combine uint and ulong values.
+ /// </summary>
+ private readonly Dictionary<int, List<FieldValue>> valuesByField = new Dictionary<int, List<FieldValue>>();
+
+ private CustomOptions() { }
+
+ /// <summary>
+ /// Retrieves a Boolean value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetBool(int field, out bool value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = tmp == 1UL;
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves a signed 32-bit integer value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetInt32(int field, out int value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = (int) tmp.GetValueOrDefault();
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves a signed 64-bit integer value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetInt64(int field, out long value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = (long) tmp.GetValueOrDefault();
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves an unsigned 32-bit integer value for the specified option field,
+ /// assuming a fixed-length representation.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetFixed32(int field, out uint value) => TryGetUInt32(field, out value);
+
+ /// <summary>
+ /// Retrieves an unsigned 64-bit integer value for the specified option field,
+ /// assuming a fixed-length representation.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetFixed64(int field, out ulong value) => TryGetUInt64(field, out value);
+
+ /// <summary>
+ /// Retrieves a signed 32-bit integer value for the specified option field,
+ /// assuming a fixed-length representation.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetSFixed32(int field, out int value) => TryGetInt32(field, out value);
+
+ /// <summary>
+ /// Retrieves a signed 64-bit integer value for the specified option field,
+ /// assuming a fixed-length representation.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetSFixed64(int field, out long value) => TryGetInt64(field, out value);
+
+ /// <summary>
+ /// Retrieves a signed 32-bit integer value for the specified option field,
+ /// assuming a zigzag encoding.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetSInt32(int field, out int value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = CodedInputStream.DecodeZigZag32((uint) tmp.GetValueOrDefault());
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves a signed 64-bit integer value for the specified option field,
+ /// assuming a zigzag encoding.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetSInt64(int field, out long value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = CodedInputStream.DecodeZigZag64(tmp.GetValueOrDefault());
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves an unsigned 32-bit integer value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetUInt32(int field, out uint value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = (uint) tmp.GetValueOrDefault();
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves an unsigned 64-bit integer value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetUInt64(int field, out ulong value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = tmp.GetValueOrDefault();
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves a 32-bit floating point value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetFloat(int field, out float value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ int int32 = (int) tmp.GetValueOrDefault();
+ byte[] bytes = BitConverter.GetBytes(int32);
+ value = BitConverter.ToSingle(bytes, 0);
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves a 64-bit floating point value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetDouble(int field, out double value)
+ {
+ ulong? tmp = GetLastNumericValue(field);
+ value = BitConverter.Int64BitsToDouble((long) tmp.GetValueOrDefault());
+ return tmp != null;
+ }
+
+ /// <summary>
+ /// Retrieves a string value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetString(int field, out string value)
+ {
+ ByteString bytes = GetLastByteStringValue(field);
+ value = bytes?.ToStringUtf8();
+ return bytes != null;
+ }
+
+ /// <summary>
+ /// Retrieves a bytes value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetBytes(int field, out ByteString value)
+ {
+ ByteString bytes = GetLastByteStringValue(field);
+ value = bytes;
+ return bytes != null;
+ }
+
+ /// <summary>
+ /// Retrieves a message value for the specified option field.
+ /// </summary>
+ /// <param name="field">The field to fetch the value for.</param>
+ /// <param name="value">The output variable to populate.</param>
+ /// <returns><c>true</c> if a suitable value for the field was found; <c>false</c> otherwise.</returns>
+ public bool TryGetMessage<T>(int field, out T value) where T : class, IMessage, new()
+ {
+ value = null;
+ List<FieldValue> values;
+ if (!valuesByField.TryGetValue(field, out values))
+ {
+ return false;
+ }
+ foreach (FieldValue fieldValue in values)
+ {
+ if (fieldValue.ByteString != null)
+ {
+ if (value == null)
+ {
+ value = new T();
+ }
+ value.MergeFrom(fieldValue.ByteString);
+ }
+ }
+ return value != null;
+ }
+
+ private ulong? GetLastNumericValue(int field)
+ {
+ List<FieldValue> values;
+ if (!valuesByField.TryGetValue(field, out values))
+ {
+ return null;
+ }
+ for (int i = values.Count - 1; i >= 0; i--)
+ {
+ // A non-bytestring value is a numeric value
+ if (values[i].ByteString == null)
+ {
+ return values[i].Number;
+ }
+ }
+ return null;
+ }
+
+ private ByteString GetLastByteStringValue(int field)
+ {
+ List<FieldValue> values;
+ if (!valuesByField.TryGetValue(field, out values))
+ {
+ return null;
+ }
+ for (int i = values.Count - 1; i >= 0; i--)
+ {
+ if (values[i].ByteString != null)
+ {
+ return values[i].ByteString;
+ }
+ }
+ return null;
+ }
+
+ /// <summary>
+ /// Reads an unknown field, either parsing it and storing it or skipping it.
+ /// </summary>
+ /// <remarks>
+ /// If the current set of options is empty and we manage to read a field, a new set of options
+ /// will be created and returned. Otherwise, the return value is <c>this</c>. This allows
+ /// us to start with a singleton empty set of options and just create new ones where necessary.
+ /// </remarks>
+ /// <param name="input">Input stream to read from. </param>
+ /// <returns>The resulting set of custom options, either <c>this</c> or a new set.</returns>
+ internal CustomOptions ReadOrSkipUnknownField(CodedInputStream input)
+ {
+ var tag = input.LastTag;
+ var field = WireFormat.GetTagFieldNumber(tag);
+ switch (WireFormat.GetTagWireType(tag))
+ {
+ case WireFormat.WireType.LengthDelimited:
+ return AddValue(field, new FieldValue(input.ReadBytes()));
+ case WireFormat.WireType.Fixed32:
+ return AddValue(field, new FieldValue(input.ReadFixed32()));
+ case WireFormat.WireType.Fixed64:
+ return AddValue(field, new FieldValue(input.ReadFixed64()));
+ case WireFormat.WireType.Varint:
+ return AddValue(field, new FieldValue(input.ReadRawVarint64()));
+ // For StartGroup, EndGroup or any wire format we don't understand,
+ // just use the normal behavior (call SkipLastField).
+ default:
+ input.SkipLastField();
+ return this;
+ }
+ }
+
+ private CustomOptions AddValue(int field, FieldValue value)
+ {
+ var ret = valuesByField.Count == 0 ? new CustomOptions() : this;
+ List<FieldValue> valuesForField;
+ if (!ret.valuesByField.TryGetValue(field, out valuesForField))
+ {
+ // Expect almost all
+ valuesForField = new List<FieldValue>(1);
+ ret.valuesByField[field] = valuesForField;
+ }
+ valuesForField.Add(value);
+ return ret;
+ }
+
+ /// <summary>
+ /// All field values can be stored as a byte string or a 64-bit integer.
+ /// This struct avoids unnecessary boxing.
+ /// </summary>
+ private struct FieldValue
+ {
+ internal ulong Number { get; }
+ internal ByteString ByteString { get; }
+
+ internal FieldValue(ulong number)
+ {
+ Number = number;
+ ByteString = null;
+ }
+
+ internal FieldValue(ByteString byteString)
+ {
+ Number = 0;
+ ByteString = byteString;
+ }
+ }
+ }
+}
diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
index d743e516..ceab9b06 100644
--- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs
@@ -2779,6 +2779,8 @@ namespace Google.Protobuf.Reflection {
get { return Descriptor; }
}
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public FileOptions() {
OnConstruction();
@@ -3299,7 +3301,7 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- input.SkipLastField();
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
break;
case 10: {
JavaPackage = input.ReadString();
@@ -3411,6 +3413,8 @@ namespace Google.Protobuf.Reflection {
get { return Descriptor; }
}
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public MessageOptions() {
OnConstruction();
@@ -3646,7 +3650,7 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- input.SkipLastField();
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
break;
case 8: {
MessageSetWireFormat = input.ReadBool();
@@ -3689,6 +3693,8 @@ namespace Google.Protobuf.Reflection {
get { return Descriptor; }
}
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public FieldOptions() {
OnConstruction();
@@ -3980,7 +3986,7 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- input.SkipLastField();
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
break;
case 8: {
ctype_ = (global::Google.Protobuf.Reflection.FieldOptions.Types.CType) input.ReadEnum();
@@ -4062,6 +4068,8 @@ namespace Google.Protobuf.Reflection {
get { return Descriptor; }
}
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public OneofOptions() {
OnConstruction();
@@ -4147,7 +4155,7 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- input.SkipLastField();
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
break;
case 7994: {
uninterpretedOption_.AddEntriesFrom(input, _repeated_uninterpretedOption_codec);
@@ -4174,6 +4182,8 @@ namespace Google.Protobuf.Reflection {
get { return Descriptor; }
}
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public EnumOptions() {
OnConstruction();
@@ -4317,7 +4327,7 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- input.SkipLastField();
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
break;
case 16: {
AllowAlias = input.ReadBool();
@@ -4352,6 +4362,8 @@ namespace Google.Protobuf.Reflection {
get { return Descriptor; }
}
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public EnumValueOptions() {
OnConstruction();
@@ -4467,7 +4479,7 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- input.SkipLastField();
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
break;
case 8: {
Deprecated = input.ReadBool();
@@ -4498,6 +4510,8 @@ namespace Google.Protobuf.Reflection {
get { return Descriptor; }
}
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public ServiceOptions() {
OnConstruction();
@@ -4613,7 +4627,7 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- input.SkipLastField();
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
break;
case 264: {
Deprecated = input.ReadBool();
@@ -4644,6 +4658,8 @@ namespace Google.Protobuf.Reflection {
get { return Descriptor; }
}
+ internal CustomOptions CustomOptions{ get; private set; } = CustomOptions.Empty;
+
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public MethodOptions() {
OnConstruction();
@@ -4783,7 +4799,7 @@ namespace Google.Protobuf.Reflection {
while ((tag = input.ReadTag()) != 0) {
switch(tag) {
default:
- input.SkipLastField();
+ CustomOptions = CustomOptions.ReadOrSkipUnknownField(input);
break;
case 264: {
Deprecated = input.ReadBool();
diff --git a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs
index c732c93a..89c73a61 100644
--- a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs
@@ -112,5 +112,10 @@ namespace Google.Protobuf.Reflection
{
return File.DescriptorPool.FindSymbol<EnumValueDescriptor>(FullName + "." + name);
}
+
+ /// <summary>
+ /// The (possibly empty) set of custom options for this enum.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
}
} \ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs
index b212ce96..8b838c68 100644
--- a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs
@@ -66,5 +66,10 @@ namespace Google.Protobuf.Reflection
/// Returns the enum descriptor that this value is part of.
/// </summary>
public EnumDescriptor EnumDescriptor { get { return enumDescriptor; } }
+
+ /// <summary>
+ /// The (possibly empty) set of custom options for this enum value.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
}
} \ No newline at end of file
diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
index ed15d0e1..2a3d5c7a 100644
--- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
@@ -251,6 +251,11 @@ namespace Google.Protobuf.Reflection
}
/// <summary>
+ /// The (possibly empty) set of custom options for this field.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
+
+ /// <summary>
/// Look up and cross-link all field types etc.
/// </summary>
internal void CrossLink()
diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
index 94efea9e..9124beee 100644
--- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
@@ -329,5 +329,10 @@ namespace Google.Protobuf.Reflection
/// The file descriptor for <c>descriptor.proto</c>.
/// </value>
public static FileDescriptor DescriptorProtoFileDescriptor { get { return DescriptorReflection.Descriptor; } }
+
+ /// <summary>
+ /// The (possibly empty) set of custom options for this file.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
}
}
diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
index 7a1cb9d5..4a0922e8 100644
--- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
@@ -221,6 +221,11 @@ namespace Google.Protobuf.Reflection
File.DescriptorPool.FindSymbol<T>(FullName + "." + name);
/// <summary>
+ /// The (possibly empty) set of custom options for this message.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
+
+ /// <summary>
/// Looks up and cross-links all fields and nested types.
/// </summary>
internal void CrossLink()
diff --git a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs
index f9539f6c..19d7f8a0 100644
--- a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs
@@ -67,6 +67,11 @@ namespace Google.Protobuf.Reflection
/// </value>
public bool IsServerStreaming { get { return proto.ServerStreaming; } }
+ /// <summary>
+ /// The (possibly empty) set of custom options for this method.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
+
internal MethodDescriptor(MethodDescriptorProto proto, FileDescriptor file,
ServiceDescriptor parent, int index)
: base(file, parent.FullName + "." + proto.Name, index)
diff --git a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs
index 22020acf..5906c2e3 100644
--- a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs
@@ -90,6 +90,11 @@ namespace Google.Protobuf.Reflection
/// </value>
public OneofAccessor Accessor { get { return accessor; } }
+ /// <summary>
+ /// The (possibly empty) set of custom options for this oneof.
+ /// </summary>
+ public CustomOptions CustomOptions => proto.Options?.CustomOptions ?? CustomOptions.Empty;
+
internal void CrossLink()
{
List<FieldDescriptor> fieldCollection = new List<FieldDescriptor>();
diff --git a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs
index cc0a5010..fe5c072c 100644
--- a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs
@@ -78,6 +78,11 @@ namespace Google.Protobuf.Reflection
return File.DescriptorPool.FindSymbol<MethodDescriptor>(FullName + "." + name);
}
+ /// <summary>
+ /// The (possibly empty) set of custom options for this service.
+ /// </summary>
+ public CustomOptions CustomOptions => Proto.Options?.CustomOptions ?? CustomOptions.Empty;
+
internal void CrossLink()
{
foreach (MethodDescriptor method in methods)