From 062c2dc24b96986ae4162c2c09d9eb38075fdbc7 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 28 Apr 2020 19:14:27 +0200 Subject: [PATCH] add back GetOption methods, but mark them as obsolete --- .../Reflection/EnumDescriptor.cs | 19 +++++++++++++++++++ .../Reflection/EnumValueDescriptor.cs | 19 +++++++++++++++++++ .../Reflection/FieldDescriptor.cs | 19 +++++++++++++++++++ .../Reflection/FileDescriptor.cs | 19 +++++++++++++++++++ .../Reflection/MessageDescriptor.cs | 19 +++++++++++++++++++ .../Reflection/MethodDescriptor.cs | 19 +++++++++++++++++++ .../Reflection/OneofDescriptor.cs | 19 +++++++++++++++++++ .../Reflection/ServiceDescriptor.cs | 19 +++++++++++++++++++ 8 files changed, 152 insertions(+) diff --git a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs index fafd5a9e08..a7a5dea65b 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs @@ -137,5 +137,24 @@ namespace Google.Protobuf.Reflection /// NOTE: A defensive copy is created each time this property is retrieved. /// public EnumOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); + + /// + /// Gets a single value enum option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + 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 + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).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 d5939192a2..5e46a7fcc0 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs @@ -82,6 +82,25 @@ namespace Google.Protobuf.Reflection /// NOTE: A defensive copy is created each time this property is retrieved. /// public EnumValueOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); + + /// + /// Gets a single value enum value option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + 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 + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).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 92cfe7b942..4e63a316e3 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -314,6 +314,25 @@ namespace Google.Protobuf.Reflection /// public FieldOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); + /// + /// Gets a single value field option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + 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 + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).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 e81ef5999c..7c800e851c 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -557,6 +557,25 @@ namespace Google.Protobuf.Reflection /// public FileOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); + /// + /// Gets a single value file option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + 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 + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).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 de4ba7e341..3c2b8be2e0 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -297,6 +297,25 @@ namespace Google.Protobuf.Reflection /// public MessageOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); + /// + /// Gets a single value message option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + 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 + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + public Collections.RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).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 150ef23261..9cd58e64d2 100644 --- a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs @@ -83,6 +83,25 @@ namespace Google.Protobuf.Reflection /// public MethodOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); + /// + /// Gets a single value method option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + 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 + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).Clone(); + } + 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 c2ff7856e6..6e32d7cd0e 100644 --- a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs @@ -127,6 +127,25 @@ namespace Google.Protobuf.Reflection /// public OneofOptions Options => (proto.Options as IDeepCloneable)?.Clone(); + /// + /// Gets a single value oneof option for this descriptor + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + 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 + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return proto.Options.GetExtension(extension).Clone(); + } + internal void CrossLink() { List fieldCollection = new List(); diff --git a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs index 8dad4a68dc..f2afbbda3f 100644 --- a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs @@ -97,6 +97,25 @@ namespace Google.Protobuf.Reflection [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 + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + 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 + /// + [Obsolete("GetOption is obsolete. Use the Options property.")] + public RepeatedField GetOption(RepeatedExtension extension) + { + return Proto.Options.GetExtension(extension).Clone(); + } + /// /// The ServiceOptions, defined in descriptor.proto. /// Custom options can be retrieved as extensions of the returned message.