diff --git a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs index 264a88a063..fafd5a9e08 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs @@ -128,24 +128,14 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this enum. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the Options property.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// - /// Gets a single value enum option for this descriptor + /// The EnumOptions, defined in descriptor.proto. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. /// - public T GetOption(Extension extension) - { - var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; - } - - /// - /// Gets a repeated value enum option for this descriptor - /// - public RepeatedField GetOption(RepeatedExtension extension) - { - return Proto.Options.GetExtension(extension).Clone(); - } + public EnumOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); } } \ 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 3933820105..d5939192a2 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs @@ -73,25 +73,15 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this enum value. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the Options property")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// - /// Gets a single value enum value option for this descriptor + /// The EnumValueOptions, defined in descriptor.proto. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. /// - public T GetOption(Extension extension) - { - var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; - } - - /// - /// Gets a repeated value enum value option for this descriptor - /// - public RepeatedField GetOption(RepeatedExtension extension) - { - return Proto.Options.GetExtension(extension).Clone(); - } + public EnumValueOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); } } \ 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 69bab4f010..92cfe7b942 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -304,25 +304,15 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this field. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the Options property.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// - /// Gets a single value field option for this descriptor + /// The FieldOptions, defined in descriptor.proto. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. /// - public T GetOption(Extension extension) - { - var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; - } - - /// - /// Gets a repeated value field option for this descriptor - /// - public RepeatedField GetOption(RepeatedExtension extension) - { - return Proto.Options.GetExtension(extension).Clone(); - } + public FieldOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); /// /// Look up and cross-link all field types etc. diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs index 56c0caacfd..e81ef5999c 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -547,25 +547,15 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this file. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the Options property.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// - /// Gets a single value file option for this descriptor + /// The FileOptions, defined in descriptor.proto. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. /// - public T GetOption(Extension extension) - { - var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; - } - - /// - /// Gets a repeated value file option for this descriptor - /// - public RepeatedField GetOption(RepeatedExtension extension) - { - return Proto.Options.GetExtension(extension).Clone(); - } + public FileOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); /// /// Performs initialization for the given generic type argument. diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index 6217081fbc..de4ba7e341 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -287,25 +287,15 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this message. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the Options property")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// - /// Gets a single value message option for this descriptor + /// The MessageOptions, defined in descriptor.proto. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. /// - public T GetOption(Extension extension) - { - var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; - } - - /// - /// Gets a repeated value message option for this descriptor - /// - public Collections.RepeatedField GetOption(RepeatedExtension extension) - { - return Proto.Options.GetExtension(extension).Clone(); - } + public MessageOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); /// /// Looks up and cross-links all fields and nested types. diff --git a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs index 92250ba662..150ef23261 100644 --- a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs @@ -73,25 +73,15 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this method. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the Options property.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// - /// Gets a single value method option for this descriptor + /// The MethodOptions, defined in descriptor.proto. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. /// - public T GetOption(Extension extension) - { - var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; - } - - /// - /// Gets a repeated value method option for this descriptor - /// - public RepeatedField GetOption(RepeatedExtension extension) - { - return Proto.Options.GetExtension(extension).Clone(); - } + public MethodOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); internal MethodDescriptor(MethodDescriptorProto proto, FileDescriptor file, ServiceDescriptor parent, int index) diff --git a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs index 7cceabd7c3..c2ff7856e6 100644 --- a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs @@ -117,25 +117,15 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this oneof. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the Options property.")] public CustomOptions CustomOptions => new CustomOptions(proto.Options?._extensions?.ValuesByNumber); /// - /// Gets a single value oneof option for this descriptor + /// The OneofOptions, defined in descriptor.proto. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. /// - public T GetOption(Extension extension) - { - var value = proto.Options.GetExtension(extension); - return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; - } - - /// - /// Gets a repeated value oneof option for this descriptor - /// - public RepeatedField GetOption(RepeatedExtension extension) - { - return proto.Options.GetExtension(extension).Clone(); - } + public OneofOptions Options => (proto.Options as IDeepCloneable)?.Clone(); internal void CrossLink() { diff --git a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs index 21417ec641..8dad4a68dc 100644 --- a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs @@ -94,25 +94,15 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this service. /// - [Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use the Options property.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// - /// Gets a single value service option for this descriptor + /// The ServiceOptions, defined in descriptor.proto. + /// Custom options can be retrieved as extensions of the returned message. + /// NOTE: A defensive copy is created each time this property is retrieved. /// - public T GetOption(Extension extension) - { - var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; - } - - /// - /// Gets a repeated value service option for this descriptor - /// - public RepeatedField GetOption(RepeatedExtension extension) - { - return Proto.Options.GetExtension(extension).Clone(); - } + public ServiceOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); internal void CrossLink() {