From 944055a68394ad589cebccedd5a234e50f749d24 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 28 Apr 2020 10:49:49 +0200 Subject: [PATCH 1/8] expose Options property on descriptors --- .../Reflection/EnumDescriptor.cs | 20 +++++-------------- .../Reflection/EnumValueDescriptor.cs | 20 +++++-------------- .../Reflection/FieldDescriptor.cs | 20 +++++-------------- .../Reflection/FileDescriptor.cs | 20 +++++-------------- .../Reflection/MessageDescriptor.cs | 20 +++++-------------- .../Reflection/MethodDescriptor.cs | 20 +++++-------------- .../Reflection/OneofDescriptor.cs | 20 +++++-------------- .../Reflection/ServiceDescriptor.cs | 20 +++++-------------- 8 files changed, 40 insertions(+), 120 deletions(-) diff --git a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs index 264a88a063bc..fafd5a9e08dd 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs @@ -128,24 +128,14 @@ public EnumValueDescriptor FindValueByName(string name) /// /// 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 393382010559..d5939192a21a 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs @@ -73,25 +73,15 @@ public sealed class EnumValueDescriptor : DescriptorBase /// /// 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 69bab4f01045..92cfe7b94260 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -304,25 +304,15 @@ public MessageDescriptor ExtendeeType /// /// 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 56c0caacfde3..e81ef5999c01 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -547,25 +547,15 @@ public override string ToString() /// /// 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 6217081fbcef..de4ba7e341ed 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -287,25 +287,15 @@ internal bool IsExtensionsInitialized(IMessage message) /// /// 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 92250ba662e0..150ef23261cb 100644 --- a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs @@ -73,25 +73,15 @@ public sealed class MethodDescriptor : DescriptorBase /// /// 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 7cceabd7c3e6..c2ff7856e612 100644 --- a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs @@ -117,25 +117,15 @@ public MessageDescriptor ContainingType /// /// 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 21417ec641e4..8dad4a68dc6e 100644 --- a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs @@ -94,25 +94,15 @@ public MethodDescriptor FindMethodByName(String name) /// /// 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() { From 9720ae41c2c25b56290fb02ed6908277d60db2be Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 28 Apr 2020 12:40:24 +0200 Subject: [PATCH 2/8] adjust CustomOptionsTest.cs --- .../Reflection/CustomOptionsTest.cs | 123 +++++++++--------- 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs index bfee5f5d439b..47b375d015e1 100644 --- a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs +++ b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs @@ -75,21 +75,21 @@ OptionFetcher EnumFetcher(CustomOptions options) public void ScalarOptions() { var d = CustomOptionOtherValues.Descriptor; - var options = d.CustomOptions; - AssertOption(-100, options.TryGetInt32, Int32Opt, d.GetOption); - AssertOption(12.3456789f, options.TryGetFloat, FloatOpt, d.GetOption); - AssertOption(1.234567890123456789d, options.TryGetDouble, DoubleOpt, d.GetOption); - AssertOption("Hello, \"World\"", options.TryGetString, StringOpt, d.GetOption); - AssertOption(ByteString.CopyFromUtf8("Hello\0World"), options.TryGetBytes, BytesOpt, d.GetOption); - AssertOption(TestEnumType.TestOptionEnumType2, EnumFetcher(options), EnumOpt, d.GetOption); + var customOptions = d.CustomOptions; + AssertOption(-100, customOptions.TryGetInt32, Int32Opt, d.Options.GetExtension); + AssertOption(12.3456789f, customOptions.TryGetFloat, FloatOpt, d.Options.GetExtension); + AssertOption(1.234567890123456789d, customOptions.TryGetDouble, DoubleOpt, d.Options.GetExtension); + AssertOption("Hello, \"World\"", customOptions.TryGetString, StringOpt, d.Options.GetExtension); + AssertOption(ByteString.CopyFromUtf8("Hello\0World"), customOptions.TryGetBytes, BytesOpt, d.Options.GetExtension); + AssertOption(TestEnumType.TestOptionEnumType2, EnumFetcher(customOptions), EnumOpt, d.Options.GetExtension); } [Test] public void MessageOptions() { var d = VariousComplexOptions.Descriptor; - var options = d.CustomOptions; - AssertOption(new ComplexOptionType1 { Foo = 42, Foo4 = { 99, 88 } }, options.TryGetMessage, ComplexOpt1, d.GetOption); + var customOptions = d.CustomOptions; + AssertOption(new ComplexOptionType1 { Foo = 42, Foo4 = { 99, 88 } }, customOptions.TryGetMessage, ComplexOpt1, d.Options.GetExtension); AssertOption(new ComplexOptionType2 { Baz = 987, @@ -97,85 +97,84 @@ public void MessageOptions() Fred = new ComplexOptionType4 { Waldo = 321 }, Barney = { new ComplexOptionType4 { Waldo = 101 }, new ComplexOptionType4 { Waldo = 212 } } }, - options.TryGetMessage, ComplexOpt2, d.GetOption); - AssertOption(new ComplexOptionType3 { Qux = 9 }, options.TryGetMessage, ComplexOpt3, d.GetOption); + customOptions.TryGetMessage, ComplexOpt2, d.Options.GetExtension); + AssertOption(new ComplexOptionType3 { Qux = 9 }, customOptions.TryGetMessage, ComplexOpt3, d.Options.GetExtension); } [Test] public void OptionLocations() { - var fileOptions = UnittestCustomOptionsProto3Reflection.Descriptor.CustomOptions; - AssertOption(9876543210UL, fileOptions.TryGetUInt64, FileOpt1, UnittestCustomOptionsProto3Reflection.Descriptor.GetOption); + var fileDescriptor = UnittestCustomOptionsProto3Reflection.Descriptor; + AssertOption(9876543210UL, fileDescriptor.CustomOptions.TryGetUInt64, FileOpt1, fileDescriptor.Options.GetExtension); - var messageOptions = TestMessageWithCustomOptions.Descriptor.CustomOptions; - AssertOption(-56, messageOptions.TryGetInt32, MessageOpt1, TestMessageWithCustomOptions.Descriptor.GetOption); + var messageDescriptor = TestMessageWithCustomOptions.Descriptor; + AssertOption(-56, messageDescriptor.CustomOptions.TryGetInt32, MessageOpt1, messageDescriptor.Options.GetExtension); - var fieldOptions = TestMessageWithCustomOptions.Descriptor.Fields["field1"].CustomOptions; - AssertOption(8765432109UL, fieldOptions.TryGetFixed64, FieldOpt1, TestMessageWithCustomOptions.Descriptor.Fields["field1"].GetOption); + var fieldDescriptor = TestMessageWithCustomOptions.Descriptor.Fields["field1"]; + AssertOption(8765432109UL, fieldDescriptor.CustomOptions.TryGetFixed64, FieldOpt1, fieldDescriptor.Options.GetExtension); - var oneofOptions = TestMessageWithCustomOptions.Descriptor.Oneofs[0].CustomOptions; - AssertOption(-99, oneofOptions.TryGetInt32, OneofOpt1, TestMessageWithCustomOptions.Descriptor.Oneofs[0].GetOption); + var oneofDescriptor = TestMessageWithCustomOptions.Descriptor.Oneofs[0]; + AssertOption(-99, oneofDescriptor.CustomOptions.TryGetInt32, OneofOpt1, oneofDescriptor.Options.GetExtension); - var enumOptions = TestMessageWithCustomOptions.Descriptor.EnumTypes[0].CustomOptions; - AssertOption(-789, enumOptions.TryGetSFixed32, EnumOpt1, TestMessageWithCustomOptions.Descriptor.EnumTypes[0].GetOption); + var enumDescriptor = TestMessageWithCustomOptions.Descriptor.EnumTypes[0]; + AssertOption(-789, enumDescriptor.CustomOptions.TryGetSFixed32, EnumOpt1, enumDescriptor.Options.GetExtension); - var enumValueOptions = TestMessageWithCustomOptions.Descriptor.EnumTypes[0].FindValueByNumber(2).CustomOptions; - AssertOption(123, enumValueOptions.TryGetInt32, EnumValueOpt1, TestMessageWithCustomOptions.Descriptor.EnumTypes[0].FindValueByNumber(2).GetOption); + var enumValueDescriptor = TestMessageWithCustomOptions.Descriptor.EnumTypes[0].FindValueByNumber(2); + AssertOption(123, enumValueDescriptor.CustomOptions.TryGetInt32, EnumValueOpt1, enumValueDescriptor.Options.GetExtension); - var service = UnittestCustomOptionsProto3Reflection.Descriptor.Services + var serviceDescriptor = UnittestCustomOptionsProto3Reflection.Descriptor.Services .Single(s => s.Name == "TestServiceWithCustomOptions"); - var serviceOptions = service.CustomOptions; - AssertOption(-9876543210, serviceOptions.TryGetSInt64, ServiceOpt1, service.GetOption); + AssertOption(-9876543210, serviceDescriptor.CustomOptions.TryGetSInt64, ServiceOpt1, serviceDescriptor.Options.GetExtension); - var methodOptions = service.Methods[0].CustomOptions; - AssertOption(UnitTest.Issues.TestProtos.MethodOpt1.Val2, EnumFetcher(methodOptions), UnittestCustomOptionsProto3Extensions.MethodOpt1, service.Methods[0].GetOption); + var methodDescriptor = serviceDescriptor.Methods[0]; + AssertOption(UnitTest.Issues.TestProtos.MethodOpt1.Val2, EnumFetcher(methodDescriptor.CustomOptions), UnittestCustomOptionsProto3Extensions.MethodOpt1, methodDescriptor.Options.GetExtension); } [Test] public void MinValues() { var d = CustomOptionMinIntegerValues.Descriptor; - var options = d.CustomOptions; - AssertOption(false, options.TryGetBool, BoolOpt, d.GetOption); - AssertOption(int.MinValue, options.TryGetInt32, Int32Opt, d.GetOption); - AssertOption(long.MinValue, options.TryGetInt64, Int64Opt, d.GetOption); - AssertOption(uint.MinValue, options.TryGetUInt32, Uint32Opt, d.GetOption); - AssertOption(ulong.MinValue, options.TryGetUInt64, Uint64Opt, d.GetOption); - AssertOption(int.MinValue, options.TryGetSInt32, Sint32Opt, d.GetOption); - AssertOption(long.MinValue, options.TryGetSInt64, Sint64Opt, d.GetOption); - AssertOption(uint.MinValue, options.TryGetUInt32, Fixed32Opt, d.GetOption); - AssertOption(ulong.MinValue, options.TryGetUInt64, Fixed64Opt, d.GetOption); - AssertOption(int.MinValue, options.TryGetInt32, Sfixed32Opt, d.GetOption); - AssertOption(long.MinValue, options.TryGetInt64, Sfixed64Opt, d.GetOption); + var customOptions = d.CustomOptions; + AssertOption(false, customOptions.TryGetBool, BoolOpt, d.Options.GetExtension); + AssertOption(int.MinValue, customOptions.TryGetInt32, Int32Opt, d.Options.GetExtension); + AssertOption(long.MinValue, customOptions.TryGetInt64, Int64Opt, d.Options.GetExtension); + AssertOption(uint.MinValue, customOptions.TryGetUInt32, Uint32Opt, d.Options.GetExtension); + AssertOption(ulong.MinValue, customOptions.TryGetUInt64, Uint64Opt, d.Options.GetExtension); + AssertOption(int.MinValue, customOptions.TryGetSInt32, Sint32Opt, d.Options.GetExtension); + AssertOption(long.MinValue, customOptions.TryGetSInt64, Sint64Opt, d.Options.GetExtension); + AssertOption(uint.MinValue, customOptions.TryGetUInt32, Fixed32Opt, d.Options.GetExtension); + AssertOption(ulong.MinValue, customOptions.TryGetUInt64, Fixed64Opt, d.Options.GetExtension); + AssertOption(int.MinValue, customOptions.TryGetInt32, Sfixed32Opt, d.Options.GetExtension); + AssertOption(long.MinValue, customOptions.TryGetInt64, Sfixed64Opt, d.Options.GetExtension); } [Test] public void MaxValues() { var d = CustomOptionMaxIntegerValues.Descriptor; - var options = d.CustomOptions; - AssertOption(true, options.TryGetBool, BoolOpt, d.GetOption); - AssertOption(int.MaxValue, options.TryGetInt32, Int32Opt, d.GetOption); - AssertOption(long.MaxValue, options.TryGetInt64, Int64Opt, d.GetOption); - AssertOption(uint.MaxValue, options.TryGetUInt32, Uint32Opt, d.GetOption); - AssertOption(ulong.MaxValue, options.TryGetUInt64, Uint64Opt, d.GetOption); - AssertOption(int.MaxValue, options.TryGetSInt32, Sint32Opt, d.GetOption); - AssertOption(long.MaxValue, options.TryGetSInt64, Sint64Opt, d.GetOption); - AssertOption(uint.MaxValue, options.TryGetFixed32, Fixed32Opt, d.GetOption); - AssertOption(ulong.MaxValue, options.TryGetFixed64, Fixed64Opt, d.GetOption); - AssertOption(int.MaxValue, options.TryGetSFixed32, Sfixed32Opt, d.GetOption); - AssertOption(long.MaxValue, options.TryGetSFixed64, Sfixed64Opt, d.GetOption); + var customOptions = d.CustomOptions; + AssertOption(true, customOptions.TryGetBool, BoolOpt, d.Options.GetExtension); + AssertOption(int.MaxValue, customOptions.TryGetInt32, Int32Opt, d.Options.GetExtension); + AssertOption(long.MaxValue, customOptions.TryGetInt64, Int64Opt, d.Options.GetExtension); + AssertOption(uint.MaxValue, customOptions.TryGetUInt32, Uint32Opt, d.Options.GetExtension); + AssertOption(ulong.MaxValue, customOptions.TryGetUInt64, Uint64Opt, d.Options.GetExtension); + AssertOption(int.MaxValue, customOptions.TryGetSInt32, Sint32Opt, d.Options.GetExtension); + AssertOption(long.MaxValue, customOptions.TryGetSInt64, Sint64Opt, d.Options.GetExtension); + AssertOption(uint.MaxValue, customOptions.TryGetFixed32, Fixed32Opt, d.Options.GetExtension); + AssertOption(ulong.MaxValue, customOptions.TryGetFixed64, Fixed64Opt, d.Options.GetExtension); + AssertOption(int.MaxValue, customOptions.TryGetSFixed32, Sfixed32Opt, d.Options.GetExtension); + AssertOption(long.MaxValue, customOptions.TryGetSFixed64, Sfixed64Opt, d.Options.GetExtension); } [Test] public void AggregateOptions() { // Just two examples - var messageOptions = AggregateMessage.Descriptor.CustomOptions; - AssertOption(new Aggregate { I = 101, S = "MessageAnnotation" }, messageOptions.TryGetMessage, Msgopt, AggregateMessage.Descriptor.GetOption); + var messageDescriptor = AggregateMessage.Descriptor; + AssertOption(new Aggregate { I = 101, S = "MessageAnnotation" }, messageDescriptor.CustomOptions.TryGetMessage, Msgopt, messageDescriptor.Options.GetExtension); - var fieldOptions = AggregateMessage.Descriptor.Fields["fieldname"].CustomOptions; - AssertOption(new Aggregate { S = "FieldAnnotation" }, fieldOptions.TryGetMessage, Fieldopt, AggregateMessage.Descriptor.Fields["fieldname"].GetOption); + var fieldDescriptor = messageDescriptor.Fields["fieldname"]; + AssertOption(new Aggregate { S = "FieldAnnotation" }, fieldDescriptor.CustomOptions.TryGetMessage, Fieldopt, fieldDescriptor.Options.GetExtension); } [Test] @@ -199,16 +198,16 @@ public void MultipleImportOfSameFileWithExtension() var descriptor = UnittestIssue6936CReflection.Descriptor; var foo = Foo.Descriptor; var bar = Bar.Descriptor; - AssertOption("foo", foo.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, foo.GetOption); - AssertOption("bar", bar.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, bar.GetOption); + AssertOption("foo", foo.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, foo.Options.GetExtension); + AssertOption("bar", bar.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, bar.Options.GetExtension); } - private void AssertOption(T expected, OptionFetcher fetcher, Extension extension, Func, T> descriptorOptionFetcher) where D : IExtendableMessage + private void AssertOption(T expected, OptionFetcher customOptionFetcher, Extension extension, Func, T> extensionFetcher) where D : IExtendableMessage { - T customOptionsValue; - T extensionValue = descriptorOptionFetcher(extension); - Assert.IsTrue(fetcher(extension.FieldNumber, out customOptionsValue)); + Assert.IsTrue(customOptionFetcher(extension.FieldNumber, out T customOptionsValue)); Assert.AreEqual(expected, customOptionsValue); + + T extensionValue = extensionFetcher(extension); Assert.AreEqual(expected, extensionValue); } } From f4ff22026bca244fe557736d5c5c2e04c31d939b Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 28 Apr 2020 13:23:41 +0200 Subject: [PATCH 3/8] add a few more tests --- .../Reflection/CustomOptionsTest.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs index 47b375d015e1..c1b613d62dc2 100644 --- a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs +++ b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs @@ -71,6 +71,30 @@ OptionFetcher EnumFetcher(CustomOptions options) }; } + [Test] + public void BuiltinOptionsCanBeRetrieved() + { + // non-custom options (that are not extensions but regular fields) can only be accessed via descriptor.Options + var fileOptions = UnittestProto3Reflection.Descriptor.Options; + Assert.AreEqual("Google.Protobuf.TestProtos", fileOptions.CsharpNamespace); + } + + [Test] + public void OptionPresenceCanBeDetected() + { + // case 1: the descriptor has no options at all so the options message is not present + Assert.IsNull(TestAllTypes.Descriptor.Options); + + // case 2: the descriptor has some options, but not the one we're looking for + // HasExtension will be false and GetExtension returns extension's default value + Assert.IsFalse(UnittestProto3Reflection.Descriptor.Options.HasExtension(FileOpt1)); + Assert.AreEqual(0, UnittestProto3Reflection.Descriptor.Options.GetExtension(FileOpt1)); + + // case 3: option is present + Assert.IsTrue(UnittestCustomOptionsProto3Reflection.Descriptor.Options.HasExtension(FileOpt1)); + Assert.AreEqual(9876543210UL, UnittestCustomOptionsProto3Reflection.Descriptor.Options.GetExtension(FileOpt1)); + } + [Test] public void ScalarOptions() { From 062c2dc24b96986ae4162c2c09d9eb38075fdbc7 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 28 Apr 2020 19:14:27 +0200 Subject: [PATCH 4/8] 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 fafd5a9e08dd..a7a5dea65b38 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs @@ -137,5 +137,24 @@ public EnumValueDescriptor FindValueByName(string name) /// 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 d5939192a21a..5e46a7fcc052 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs @@ -82,6 +82,25 @@ public sealed class EnumValueDescriptor : DescriptorBase /// 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 92cfe7b94260..4e63a316e3d8 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -314,6 +314,25 @@ public MessageDescriptor ExtendeeType /// 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 e81ef5999c01..7c800e851c4f 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -557,6 +557,25 @@ public override string ToString() /// 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 de4ba7e341ed..3c2b8be2e071 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -297,6 +297,25 @@ internal bool IsExtensionsInitialized(IMessage message) /// 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 150ef23261cb..9cd58e64d205 100644 --- a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs @@ -83,6 +83,25 @@ public sealed class MethodDescriptor : DescriptorBase /// 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 c2ff7856e612..6e32d7cd0ed4 100644 --- a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs @@ -127,6 +127,25 @@ public MessageDescriptor ContainingType /// 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 8dad4a68dc6e..f2afbbda3f26 100644 --- a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs @@ -97,6 +97,25 @@ public MethodDescriptor FindMethodByName(String name) [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. From 402ce8b17f7141cb47a3e32480c10384d6c6236c Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 28 Apr 2020 19:25:06 +0200 Subject: [PATCH 5/8] add back GetOption tests --- .../Reflection/CustomOptionsTest.cs | 91 ++++++++++--------- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs index c1b613d62dc2..eb6629849c69 100644 --- a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs +++ b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs @@ -100,12 +100,12 @@ public void ScalarOptions() { var d = CustomOptionOtherValues.Descriptor; var customOptions = d.CustomOptions; - AssertOption(-100, customOptions.TryGetInt32, Int32Opt, d.Options.GetExtension); - AssertOption(12.3456789f, customOptions.TryGetFloat, FloatOpt, d.Options.GetExtension); - AssertOption(1.234567890123456789d, customOptions.TryGetDouble, DoubleOpt, d.Options.GetExtension); - AssertOption("Hello, \"World\"", customOptions.TryGetString, StringOpt, d.Options.GetExtension); - AssertOption(ByteString.CopyFromUtf8("Hello\0World"), customOptions.TryGetBytes, BytesOpt, d.Options.GetExtension); - AssertOption(TestEnumType.TestOptionEnumType2, EnumFetcher(customOptions), EnumOpt, d.Options.GetExtension); + AssertOption(-100, customOptions.TryGetInt32, Int32Opt, d.GetOption, d.Options.GetExtension); + AssertOption(12.3456789f, customOptions.TryGetFloat, FloatOpt, d.GetOption, d.Options.GetExtension); + AssertOption(1.234567890123456789d, customOptions.TryGetDouble, DoubleOpt, d.GetOption, d.Options.GetExtension); + AssertOption("Hello, \"World\"", customOptions.TryGetString, StringOpt, d.GetOption, d.Options.GetExtension); + AssertOption(ByteString.CopyFromUtf8("Hello\0World"), customOptions.TryGetBytes, BytesOpt, d.GetOption, d.Options.GetExtension); + AssertOption(TestEnumType.TestOptionEnumType2, EnumFetcher(customOptions), EnumOpt, d.GetOption, d.Options.GetExtension); } [Test] @@ -113,7 +113,7 @@ public void MessageOptions() { var d = VariousComplexOptions.Descriptor; var customOptions = d.CustomOptions; - AssertOption(new ComplexOptionType1 { Foo = 42, Foo4 = { 99, 88 } }, customOptions.TryGetMessage, ComplexOpt1, d.Options.GetExtension); + AssertOption(new ComplexOptionType1 { Foo = 42, Foo4 = { 99, 88 } }, customOptions.TryGetMessage, ComplexOpt1, d.GetOption, d.Options.GetExtension); AssertOption(new ComplexOptionType2 { Baz = 987, @@ -121,37 +121,37 @@ public void MessageOptions() Fred = new ComplexOptionType4 { Waldo = 321 }, Barney = { new ComplexOptionType4 { Waldo = 101 }, new ComplexOptionType4 { Waldo = 212 } } }, - customOptions.TryGetMessage, ComplexOpt2, d.Options.GetExtension); - AssertOption(new ComplexOptionType3 { Qux = 9 }, customOptions.TryGetMessage, ComplexOpt3, d.Options.GetExtension); + customOptions.TryGetMessage, ComplexOpt2, d.GetOption, d.Options.GetExtension); + AssertOption(new ComplexOptionType3 { Qux = 9 }, customOptions.TryGetMessage, ComplexOpt3, d.GetOption, d.Options.GetExtension); } [Test] public void OptionLocations() { var fileDescriptor = UnittestCustomOptionsProto3Reflection.Descriptor; - AssertOption(9876543210UL, fileDescriptor.CustomOptions.TryGetUInt64, FileOpt1, fileDescriptor.Options.GetExtension); + AssertOption(9876543210UL, fileDescriptor.CustomOptions.TryGetUInt64, FileOpt1, fileDescriptor.GetOption, fileDescriptor.Options.GetExtension); var messageDescriptor = TestMessageWithCustomOptions.Descriptor; - AssertOption(-56, messageDescriptor.CustomOptions.TryGetInt32, MessageOpt1, messageDescriptor.Options.GetExtension); + AssertOption(-56, messageDescriptor.CustomOptions.TryGetInt32, MessageOpt1, messageDescriptor.GetOption, messageDescriptor.Options.GetExtension); var fieldDescriptor = TestMessageWithCustomOptions.Descriptor.Fields["field1"]; - AssertOption(8765432109UL, fieldDescriptor.CustomOptions.TryGetFixed64, FieldOpt1, fieldDescriptor.Options.GetExtension); + AssertOption(8765432109UL, fieldDescriptor.CustomOptions.TryGetFixed64, FieldOpt1, fieldDescriptor.GetOption, fieldDescriptor.Options.GetExtension); var oneofDescriptor = TestMessageWithCustomOptions.Descriptor.Oneofs[0]; - AssertOption(-99, oneofDescriptor.CustomOptions.TryGetInt32, OneofOpt1, oneofDescriptor.Options.GetExtension); + AssertOption(-99, oneofDescriptor.CustomOptions.TryGetInt32, OneofOpt1, oneofDescriptor.GetOption, oneofDescriptor.Options.GetExtension); var enumDescriptor = TestMessageWithCustomOptions.Descriptor.EnumTypes[0]; - AssertOption(-789, enumDescriptor.CustomOptions.TryGetSFixed32, EnumOpt1, enumDescriptor.Options.GetExtension); + AssertOption(-789, enumDescriptor.CustomOptions.TryGetSFixed32, EnumOpt1, enumDescriptor.GetOption, enumDescriptor.Options.GetExtension); var enumValueDescriptor = TestMessageWithCustomOptions.Descriptor.EnumTypes[0].FindValueByNumber(2); - AssertOption(123, enumValueDescriptor.CustomOptions.TryGetInt32, EnumValueOpt1, enumValueDescriptor.Options.GetExtension); + AssertOption(123, enumValueDescriptor.CustomOptions.TryGetInt32, EnumValueOpt1, enumValueDescriptor.GetOption, enumValueDescriptor.Options.GetExtension); var serviceDescriptor = UnittestCustomOptionsProto3Reflection.Descriptor.Services .Single(s => s.Name == "TestServiceWithCustomOptions"); - AssertOption(-9876543210, serviceDescriptor.CustomOptions.TryGetSInt64, ServiceOpt1, serviceDescriptor.Options.GetExtension); + AssertOption(-9876543210, serviceDescriptor.CustomOptions.TryGetSInt64, ServiceOpt1, serviceDescriptor.GetOption, serviceDescriptor.Options.GetExtension); var methodDescriptor = serviceDescriptor.Methods[0]; - AssertOption(UnitTest.Issues.TestProtos.MethodOpt1.Val2, EnumFetcher(methodDescriptor.CustomOptions), UnittestCustomOptionsProto3Extensions.MethodOpt1, methodDescriptor.Options.GetExtension); + AssertOption(UnitTest.Issues.TestProtos.MethodOpt1.Val2, EnumFetcher(methodDescriptor.CustomOptions), UnittestCustomOptionsProto3Extensions.MethodOpt1, methodDescriptor.GetOption, methodDescriptor.Options.GetExtension); } [Test] @@ -159,17 +159,17 @@ public void MinValues() { var d = CustomOptionMinIntegerValues.Descriptor; var customOptions = d.CustomOptions; - AssertOption(false, customOptions.TryGetBool, BoolOpt, d.Options.GetExtension); - AssertOption(int.MinValue, customOptions.TryGetInt32, Int32Opt, d.Options.GetExtension); - AssertOption(long.MinValue, customOptions.TryGetInt64, Int64Opt, d.Options.GetExtension); - AssertOption(uint.MinValue, customOptions.TryGetUInt32, Uint32Opt, d.Options.GetExtension); - AssertOption(ulong.MinValue, customOptions.TryGetUInt64, Uint64Opt, d.Options.GetExtension); - AssertOption(int.MinValue, customOptions.TryGetSInt32, Sint32Opt, d.Options.GetExtension); - AssertOption(long.MinValue, customOptions.TryGetSInt64, Sint64Opt, d.Options.GetExtension); - AssertOption(uint.MinValue, customOptions.TryGetUInt32, Fixed32Opt, d.Options.GetExtension); - AssertOption(ulong.MinValue, customOptions.TryGetUInt64, Fixed64Opt, d.Options.GetExtension); - AssertOption(int.MinValue, customOptions.TryGetInt32, Sfixed32Opt, d.Options.GetExtension); - AssertOption(long.MinValue, customOptions.TryGetInt64, Sfixed64Opt, d.Options.GetExtension); + AssertOption(false, customOptions.TryGetBool, BoolOpt, d.GetOption, d.Options.GetExtension); + AssertOption(int.MinValue, customOptions.TryGetInt32, Int32Opt, d.GetOption, d.Options.GetExtension); + AssertOption(long.MinValue, customOptions.TryGetInt64, Int64Opt, d.GetOption, d.Options.GetExtension); + AssertOption(uint.MinValue, customOptions.TryGetUInt32, Uint32Opt, d.GetOption, d.Options.GetExtension); + AssertOption(ulong.MinValue, customOptions.TryGetUInt64, Uint64Opt, d.GetOption, d.Options.GetExtension); + AssertOption(int.MinValue, customOptions.TryGetSInt32, Sint32Opt, d.GetOption, d.Options.GetExtension); + AssertOption(long.MinValue, customOptions.TryGetSInt64, Sint64Opt, d.GetOption, d.Options.GetExtension); + AssertOption(uint.MinValue, customOptions.TryGetUInt32, Fixed32Opt, d.GetOption, d.Options.GetExtension); + AssertOption(ulong.MinValue, customOptions.TryGetUInt64, Fixed64Opt, d.GetOption, d.Options.GetExtension); + AssertOption(int.MinValue, customOptions.TryGetInt32, Sfixed32Opt, d.GetOption, d.Options.GetExtension); + AssertOption(long.MinValue, customOptions.TryGetInt64, Sfixed64Opt, d.GetOption, d.Options.GetExtension); } [Test] @@ -177,17 +177,17 @@ public void MaxValues() { var d = CustomOptionMaxIntegerValues.Descriptor; var customOptions = d.CustomOptions; - AssertOption(true, customOptions.TryGetBool, BoolOpt, d.Options.GetExtension); - AssertOption(int.MaxValue, customOptions.TryGetInt32, Int32Opt, d.Options.GetExtension); - AssertOption(long.MaxValue, customOptions.TryGetInt64, Int64Opt, d.Options.GetExtension); - AssertOption(uint.MaxValue, customOptions.TryGetUInt32, Uint32Opt, d.Options.GetExtension); - AssertOption(ulong.MaxValue, customOptions.TryGetUInt64, Uint64Opt, d.Options.GetExtension); - AssertOption(int.MaxValue, customOptions.TryGetSInt32, Sint32Opt, d.Options.GetExtension); - AssertOption(long.MaxValue, customOptions.TryGetSInt64, Sint64Opt, d.Options.GetExtension); - AssertOption(uint.MaxValue, customOptions.TryGetFixed32, Fixed32Opt, d.Options.GetExtension); - AssertOption(ulong.MaxValue, customOptions.TryGetFixed64, Fixed64Opt, d.Options.GetExtension); - AssertOption(int.MaxValue, customOptions.TryGetSFixed32, Sfixed32Opt, d.Options.GetExtension); - AssertOption(long.MaxValue, customOptions.TryGetSFixed64, Sfixed64Opt, d.Options.GetExtension); + AssertOption(true, customOptions.TryGetBool, BoolOpt, d.GetOption, d.Options.GetExtension); + AssertOption(int.MaxValue, customOptions.TryGetInt32, Int32Opt, d.GetOption, d.Options.GetExtension); + AssertOption(long.MaxValue, customOptions.TryGetInt64, Int64Opt, d.GetOption, d.Options.GetExtension); + AssertOption(uint.MaxValue, customOptions.TryGetUInt32, Uint32Opt, d.GetOption, d.Options.GetExtension); + AssertOption(ulong.MaxValue, customOptions.TryGetUInt64, Uint64Opt, d.GetOption, d.Options.GetExtension); + AssertOption(int.MaxValue, customOptions.TryGetSInt32, Sint32Opt, d.GetOption, d.Options.GetExtension); + AssertOption(long.MaxValue, customOptions.TryGetSInt64, Sint64Opt, d.GetOption, d.Options.GetExtension); + AssertOption(uint.MaxValue, customOptions.TryGetFixed32, Fixed32Opt, d.GetOption, d.Options.GetExtension); + AssertOption(ulong.MaxValue, customOptions.TryGetFixed64, Fixed64Opt, d.GetOption, d.Options.GetExtension); + AssertOption(int.MaxValue, customOptions.TryGetSFixed32, Sfixed32Opt, d.GetOption, d.Options.GetExtension); + AssertOption(long.MaxValue, customOptions.TryGetSFixed64, Sfixed64Opt, d.GetOption, d.Options.GetExtension); } [Test] @@ -195,10 +195,10 @@ public void AggregateOptions() { // Just two examples var messageDescriptor = AggregateMessage.Descriptor; - AssertOption(new Aggregate { I = 101, S = "MessageAnnotation" }, messageDescriptor.CustomOptions.TryGetMessage, Msgopt, messageDescriptor.Options.GetExtension); + AssertOption(new Aggregate { I = 101, S = "MessageAnnotation" }, messageDescriptor.CustomOptions.TryGetMessage, Msgopt, messageDescriptor.GetOption, messageDescriptor.Options.GetExtension); var fieldDescriptor = messageDescriptor.Fields["fieldname"]; - AssertOption(new Aggregate { S = "FieldAnnotation" }, fieldDescriptor.CustomOptions.TryGetMessage, Fieldopt, fieldDescriptor.Options.GetExtension); + AssertOption(new Aggregate { S = "FieldAnnotation" }, fieldDescriptor.CustomOptions.TryGetMessage, Fieldopt, fieldDescriptor.GetOption, fieldDescriptor.Options.GetExtension); } [Test] @@ -222,15 +222,18 @@ public void MultipleImportOfSameFileWithExtension() var descriptor = UnittestIssue6936CReflection.Descriptor; var foo = Foo.Descriptor; var bar = Bar.Descriptor; - AssertOption("foo", foo.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, foo.Options.GetExtension); - AssertOption("bar", bar.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, bar.Options.GetExtension); + AssertOption("foo", foo.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, foo.GetOption, foo.Options.GetExtension); + AssertOption("bar", bar.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, bar.GetOption, bar.Options.GetExtension); } - private void AssertOption(T expected, OptionFetcher customOptionFetcher, Extension extension, Func, T> extensionFetcher) where D : IExtendableMessage + private void AssertOption(T expected, OptionFetcher customOptionFetcher, Extension extension, Func, T> getOptionFetcher, Func, T> extensionFetcher) where D : IExtendableMessage { Assert.IsTrue(customOptionFetcher(extension.FieldNumber, out T customOptionsValue)); Assert.AreEqual(expected, customOptionsValue); + T getOptionValue = getOptionFetcher(extension); + Assert.AreEqual(expected, getOptionValue); + T extensionValue = extensionFetcher(extension); Assert.AreEqual(expected, extensionValue); } From 673245f212e461eaa2a123bf5ebefa1fc5f96df2 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 29 Apr 2020 08:50:59 +0200 Subject: [PATCH 6/8] remove unnecessary cast --- .../Google.Protobuf/Reflection/EnumDescriptor.cs | 2 +- .../Reflection/EnumValueDescriptor.cs | 2 +- .../Google.Protobuf/Reflection/FieldDescriptor.cs | 2 +- .../Google.Protobuf/Reflection/FileDescriptor.cs | 2 +- .../Reflection/MessageDescriptor.cs | 2 +- .../Google.Protobuf/Reflection/MethodDescriptor.cs | 2 +- .../Google.Protobuf/Reflection/OneofDescriptor.cs | 2 +- .../Reflection/ServiceDescriptor.cs | 14 +++++++------- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs index a7a5dea65b38..6d0925475cb3 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs @@ -136,7 +136,7 @@ public EnumValueDescriptor FindValueByName(string name) /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public EnumOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); + public EnumOptions Options => Proto.Options?.Clone(); /// /// Gets a single value enum option for this descriptor diff --git a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs index 5e46a7fcc052..19daec8eb802 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs @@ -81,7 +81,7 @@ public sealed class EnumValueDescriptor : DescriptorBase /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public EnumValueOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); + public EnumValueOptions Options => Proto.Options?.Clone(); /// /// Gets a single value enum value option for this descriptor diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs index 4e63a316e3d8..6f8c2aec46fe 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -312,7 +312,7 @@ public MessageDescriptor ExtendeeType /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public FieldOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); + public FieldOptions Options => Proto.Options?.Clone(); /// /// Gets a single value field option for this descriptor diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs index 7c800e851c4f..b3dab3a688af 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -555,7 +555,7 @@ public override string ToString() /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public FileOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); + public FileOptions Options => Proto.Options?.Clone(); /// /// Gets a single value file option for this descriptor diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index 3c2b8be2e071..0a1d3521537c 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -295,7 +295,7 @@ internal bool IsExtensionsInitialized(IMessage message) /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public MessageOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); + public MessageOptions Options => Proto.Options?.Clone(); /// /// Gets a single value message option for this descriptor diff --git a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs index 9cd58e64d205..b42d454f847e 100644 --- a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs @@ -81,7 +81,7 @@ public sealed class MethodDescriptor : DescriptorBase /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public MethodOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); + public MethodOptions Options => Proto.Options?.Clone(); /// /// Gets a single value method option for this descriptor diff --git a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs index 6e32d7cd0ed4..d959e078eb76 100644 --- a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs @@ -125,7 +125,7 @@ public MessageDescriptor ContainingType /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public OneofOptions Options => (proto.Options as IDeepCloneable)?.Clone(); + public OneofOptions Options => proto.Options?.Clone(); /// /// Gets a single value oneof option for this descriptor diff --git a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs index f2afbbda3f26..b56e157de857 100644 --- a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs @@ -97,6 +97,13 @@ public MethodDescriptor FindMethodByName(String name) [Obsolete("CustomOptions are obsolete. Use the Options property.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); + /// + /// 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 ServiceOptions Options => Proto.Options?.Clone(); + /// /// Gets a single value service option for this descriptor /// @@ -116,13 +123,6 @@ public RepeatedField GetOption(RepeatedExtension extens return Proto.Options.GetExtension(extension).Clone(); } - /// - /// 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 ServiceOptions Options => (Proto.Options as IDeepCloneable)?.Clone(); - internal void CrossLink() { foreach (MethodDescriptor method in methods) From ff999c9d424fd76acd89c80eeacf0224a7692e3b Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 29 Apr 2020 08:57:53 +0200 Subject: [PATCH 7/8] clarify docs --- csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs | 1 + csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs | 1 + csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs | 1 + csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs | 1 + csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs | 1 + csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs | 1 + csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs | 1 + csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs | 1 + 8 files changed, 8 insertions(+) diff --git a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs index 6d0925475cb3..795a95feeb54 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs @@ -133,6 +133,7 @@ public EnumValueDescriptor FindValueByName(string name) /// /// The EnumOptions, defined in descriptor.proto. + /// If the options message is not present (=there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// diff --git a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs index 19daec8eb802..291ab8c58f8b 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs @@ -78,6 +78,7 @@ public sealed class EnumValueDescriptor : DescriptorBase /// /// The EnumValueOptions, defined in descriptor.proto. + /// If the options message is not present (=there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs index 6f8c2aec46fe..6ce606a3dfa2 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -309,6 +309,7 @@ public MessageDescriptor ExtendeeType /// /// The FieldOptions, defined in descriptor.proto. + /// If the options message is not present (=there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs index b3dab3a688af..9b298935da47 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -552,6 +552,7 @@ public override string ToString() /// /// The FileOptions, defined in descriptor.proto. + /// If the options message is not present (=there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index 0a1d3521537c..9746bc89e464 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -292,6 +292,7 @@ internal bool IsExtensionsInitialized(IMessage message) /// /// The MessageOptions, defined in descriptor.proto. + /// If the options message is not present (=there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// diff --git a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs index b42d454f847e..b7c426d916f1 100644 --- a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs @@ -78,6 +78,7 @@ public sealed class MethodDescriptor : DescriptorBase /// /// The MethodOptions, defined in descriptor.proto. + /// If the options message is not present (=there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// diff --git a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs index d959e078eb76..302e66e23291 100644 --- a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs @@ -122,6 +122,7 @@ public MessageDescriptor ContainingType /// /// The OneofOptions, defined in descriptor.proto. + /// If the options message is not present (=there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// diff --git a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs index b56e157de857..f478db05ecc4 100644 --- a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs @@ -99,6 +99,7 @@ public MethodDescriptor FindMethodByName(String name) /// /// The ServiceOptions, defined in descriptor.proto. + /// If the options message is not present (=there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// From 0688883b5264799f671377de795c1310b926e754 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 6 May 2020 18:53:36 +0200 Subject: [PATCH 8/8] address review comments --- .../Reflection/CustomOptionsTest.cs | 98 +++++++++---------- .../Reflection/EnumDescriptor.cs | 10 +- .../Reflection/EnumValueDescriptor.cs | 10 +- .../Reflection/FieldDescriptor.cs | 10 +- .../Reflection/FileDescriptor.cs | 10 +- .../Reflection/MessageDescriptor.cs | 10 +- .../Reflection/MethodDescriptor.cs | 10 +- .../Reflection/OneofDescriptor.cs | 10 +- .../Reflection/ServiceDescriptor.cs | 10 +- 9 files changed, 89 insertions(+), 89 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs index eb6629849c69..d066baec9375 100644 --- a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs +++ b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs @@ -75,7 +75,7 @@ OptionFetcher EnumFetcher(CustomOptions options) public void BuiltinOptionsCanBeRetrieved() { // non-custom options (that are not extensions but regular fields) can only be accessed via descriptor.Options - var fileOptions = UnittestProto3Reflection.Descriptor.Options; + var fileOptions = UnittestProto3Reflection.Descriptor.GetOptions(); Assert.AreEqual("Google.Protobuf.TestProtos", fileOptions.CsharpNamespace); } @@ -83,16 +83,16 @@ public void BuiltinOptionsCanBeRetrieved() public void OptionPresenceCanBeDetected() { // case 1: the descriptor has no options at all so the options message is not present - Assert.IsNull(TestAllTypes.Descriptor.Options); + Assert.IsNull(TestAllTypes.Descriptor.GetOptions()); // case 2: the descriptor has some options, but not the one we're looking for // HasExtension will be false and GetExtension returns extension's default value - Assert.IsFalse(UnittestProto3Reflection.Descriptor.Options.HasExtension(FileOpt1)); - Assert.AreEqual(0, UnittestProto3Reflection.Descriptor.Options.GetExtension(FileOpt1)); + Assert.IsFalse(UnittestProto3Reflection.Descriptor.GetOptions().HasExtension(FileOpt1)); + Assert.AreEqual(0, UnittestProto3Reflection.Descriptor.GetOptions().GetExtension(FileOpt1)); // case 3: option is present - Assert.IsTrue(UnittestCustomOptionsProto3Reflection.Descriptor.Options.HasExtension(FileOpt1)); - Assert.AreEqual(9876543210UL, UnittestCustomOptionsProto3Reflection.Descriptor.Options.GetExtension(FileOpt1)); + Assert.IsTrue(UnittestCustomOptionsProto3Reflection.Descriptor.GetOptions().HasExtension(FileOpt1)); + Assert.AreEqual(9876543210UL, UnittestCustomOptionsProto3Reflection.Descriptor.GetOptions().GetExtension(FileOpt1)); } [Test] @@ -100,12 +100,12 @@ public void ScalarOptions() { var d = CustomOptionOtherValues.Descriptor; var customOptions = d.CustomOptions; - AssertOption(-100, customOptions.TryGetInt32, Int32Opt, d.GetOption, d.Options.GetExtension); - AssertOption(12.3456789f, customOptions.TryGetFloat, FloatOpt, d.GetOption, d.Options.GetExtension); - AssertOption(1.234567890123456789d, customOptions.TryGetDouble, DoubleOpt, d.GetOption, d.Options.GetExtension); - AssertOption("Hello, \"World\"", customOptions.TryGetString, StringOpt, d.GetOption, d.Options.GetExtension); - AssertOption(ByteString.CopyFromUtf8("Hello\0World"), customOptions.TryGetBytes, BytesOpt, d.GetOption, d.Options.GetExtension); - AssertOption(TestEnumType.TestOptionEnumType2, EnumFetcher(customOptions), EnumOpt, d.GetOption, d.Options.GetExtension); + AssertOption(-100, customOptions.TryGetInt32, Int32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(12.3456789f, customOptions.TryGetFloat, FloatOpt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(1.234567890123456789d, customOptions.TryGetDouble, DoubleOpt, d.GetOption, d.GetOptions().GetExtension); + AssertOption("Hello, \"World\"", customOptions.TryGetString, StringOpt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(ByteString.CopyFromUtf8("Hello\0World"), customOptions.TryGetBytes, BytesOpt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(TestEnumType.TestOptionEnumType2, EnumFetcher(customOptions), EnumOpt, d.GetOption, d.GetOptions().GetExtension); } [Test] @@ -113,7 +113,7 @@ public void MessageOptions() { var d = VariousComplexOptions.Descriptor; var customOptions = d.CustomOptions; - AssertOption(new ComplexOptionType1 { Foo = 42, Foo4 = { 99, 88 } }, customOptions.TryGetMessage, ComplexOpt1, d.GetOption, d.Options.GetExtension); + AssertOption(new ComplexOptionType1 { Foo = 42, Foo4 = { 99, 88 } }, customOptions.TryGetMessage, ComplexOpt1, d.GetOption, d.GetOptions().GetExtension); AssertOption(new ComplexOptionType2 { Baz = 987, @@ -121,37 +121,37 @@ public void MessageOptions() Fred = new ComplexOptionType4 { Waldo = 321 }, Barney = { new ComplexOptionType4 { Waldo = 101 }, new ComplexOptionType4 { Waldo = 212 } } }, - customOptions.TryGetMessage, ComplexOpt2, d.GetOption, d.Options.GetExtension); - AssertOption(new ComplexOptionType3 { Qux = 9 }, customOptions.TryGetMessage, ComplexOpt3, d.GetOption, d.Options.GetExtension); + customOptions.TryGetMessage, ComplexOpt2, d.GetOption, d.GetOptions().GetExtension); + AssertOption(new ComplexOptionType3 { Qux = 9 }, customOptions.TryGetMessage, ComplexOpt3, d.GetOption, d.GetOptions().GetExtension); } [Test] public void OptionLocations() { var fileDescriptor = UnittestCustomOptionsProto3Reflection.Descriptor; - AssertOption(9876543210UL, fileDescriptor.CustomOptions.TryGetUInt64, FileOpt1, fileDescriptor.GetOption, fileDescriptor.Options.GetExtension); + AssertOption(9876543210UL, fileDescriptor.CustomOptions.TryGetUInt64, FileOpt1, fileDescriptor.GetOption, fileDescriptor.GetOptions().GetExtension); var messageDescriptor = TestMessageWithCustomOptions.Descriptor; - AssertOption(-56, messageDescriptor.CustomOptions.TryGetInt32, MessageOpt1, messageDescriptor.GetOption, messageDescriptor.Options.GetExtension); + AssertOption(-56, messageDescriptor.CustomOptions.TryGetInt32, MessageOpt1, messageDescriptor.GetOption, messageDescriptor.GetOptions().GetExtension); var fieldDescriptor = TestMessageWithCustomOptions.Descriptor.Fields["field1"]; - AssertOption(8765432109UL, fieldDescriptor.CustomOptions.TryGetFixed64, FieldOpt1, fieldDescriptor.GetOption, fieldDescriptor.Options.GetExtension); + AssertOption(8765432109UL, fieldDescriptor.CustomOptions.TryGetFixed64, FieldOpt1, fieldDescriptor.GetOption, fieldDescriptor.GetOptions().GetExtension); var oneofDescriptor = TestMessageWithCustomOptions.Descriptor.Oneofs[0]; - AssertOption(-99, oneofDescriptor.CustomOptions.TryGetInt32, OneofOpt1, oneofDescriptor.GetOption, oneofDescriptor.Options.GetExtension); + AssertOption(-99, oneofDescriptor.CustomOptions.TryGetInt32, OneofOpt1, oneofDescriptor.GetOption, oneofDescriptor.GetOptions().GetExtension); var enumDescriptor = TestMessageWithCustomOptions.Descriptor.EnumTypes[0]; - AssertOption(-789, enumDescriptor.CustomOptions.TryGetSFixed32, EnumOpt1, enumDescriptor.GetOption, enumDescriptor.Options.GetExtension); + AssertOption(-789, enumDescriptor.CustomOptions.TryGetSFixed32, EnumOpt1, enumDescriptor.GetOption, enumDescriptor.GetOptions().GetExtension); var enumValueDescriptor = TestMessageWithCustomOptions.Descriptor.EnumTypes[0].FindValueByNumber(2); - AssertOption(123, enumValueDescriptor.CustomOptions.TryGetInt32, EnumValueOpt1, enumValueDescriptor.GetOption, enumValueDescriptor.Options.GetExtension); + AssertOption(123, enumValueDescriptor.CustomOptions.TryGetInt32, EnumValueOpt1, enumValueDescriptor.GetOption, enumValueDescriptor.GetOptions().GetExtension); var serviceDescriptor = UnittestCustomOptionsProto3Reflection.Descriptor.Services .Single(s => s.Name == "TestServiceWithCustomOptions"); - AssertOption(-9876543210, serviceDescriptor.CustomOptions.TryGetSInt64, ServiceOpt1, serviceDescriptor.GetOption, serviceDescriptor.Options.GetExtension); + AssertOption(-9876543210, serviceDescriptor.CustomOptions.TryGetSInt64, ServiceOpt1, serviceDescriptor.GetOption, serviceDescriptor.GetOptions().GetExtension); var methodDescriptor = serviceDescriptor.Methods[0]; - AssertOption(UnitTest.Issues.TestProtos.MethodOpt1.Val2, EnumFetcher(methodDescriptor.CustomOptions), UnittestCustomOptionsProto3Extensions.MethodOpt1, methodDescriptor.GetOption, methodDescriptor.Options.GetExtension); + AssertOption(UnitTest.Issues.TestProtos.MethodOpt1.Val2, EnumFetcher(methodDescriptor.CustomOptions), UnittestCustomOptionsProto3Extensions.MethodOpt1, methodDescriptor.GetOption, methodDescriptor.GetOptions().GetExtension); } [Test] @@ -159,17 +159,17 @@ public void MinValues() { var d = CustomOptionMinIntegerValues.Descriptor; var customOptions = d.CustomOptions; - AssertOption(false, customOptions.TryGetBool, BoolOpt, d.GetOption, d.Options.GetExtension); - AssertOption(int.MinValue, customOptions.TryGetInt32, Int32Opt, d.GetOption, d.Options.GetExtension); - AssertOption(long.MinValue, customOptions.TryGetInt64, Int64Opt, d.GetOption, d.Options.GetExtension); - AssertOption(uint.MinValue, customOptions.TryGetUInt32, Uint32Opt, d.GetOption, d.Options.GetExtension); - AssertOption(ulong.MinValue, customOptions.TryGetUInt64, Uint64Opt, d.GetOption, d.Options.GetExtension); - AssertOption(int.MinValue, customOptions.TryGetSInt32, Sint32Opt, d.GetOption, d.Options.GetExtension); - AssertOption(long.MinValue, customOptions.TryGetSInt64, Sint64Opt, d.GetOption, d.Options.GetExtension); - AssertOption(uint.MinValue, customOptions.TryGetUInt32, Fixed32Opt, d.GetOption, d.Options.GetExtension); - AssertOption(ulong.MinValue, customOptions.TryGetUInt64, Fixed64Opt, d.GetOption, d.Options.GetExtension); - AssertOption(int.MinValue, customOptions.TryGetInt32, Sfixed32Opt, d.GetOption, d.Options.GetExtension); - AssertOption(long.MinValue, customOptions.TryGetInt64, Sfixed64Opt, d.GetOption, d.Options.GetExtension); + AssertOption(false, customOptions.TryGetBool, BoolOpt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(int.MinValue, customOptions.TryGetInt32, Int32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(long.MinValue, customOptions.TryGetInt64, Int64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(uint.MinValue, customOptions.TryGetUInt32, Uint32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(ulong.MinValue, customOptions.TryGetUInt64, Uint64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(int.MinValue, customOptions.TryGetSInt32, Sint32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(long.MinValue, customOptions.TryGetSInt64, Sint64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(uint.MinValue, customOptions.TryGetUInt32, Fixed32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(ulong.MinValue, customOptions.TryGetUInt64, Fixed64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(int.MinValue, customOptions.TryGetInt32, Sfixed32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(long.MinValue, customOptions.TryGetInt64, Sfixed64Opt, d.GetOption, d.GetOptions().GetExtension); } [Test] @@ -177,17 +177,17 @@ public void MaxValues() { var d = CustomOptionMaxIntegerValues.Descriptor; var customOptions = d.CustomOptions; - AssertOption(true, customOptions.TryGetBool, BoolOpt, d.GetOption, d.Options.GetExtension); - AssertOption(int.MaxValue, customOptions.TryGetInt32, Int32Opt, d.GetOption, d.Options.GetExtension); - AssertOption(long.MaxValue, customOptions.TryGetInt64, Int64Opt, d.GetOption, d.Options.GetExtension); - AssertOption(uint.MaxValue, customOptions.TryGetUInt32, Uint32Opt, d.GetOption, d.Options.GetExtension); - AssertOption(ulong.MaxValue, customOptions.TryGetUInt64, Uint64Opt, d.GetOption, d.Options.GetExtension); - AssertOption(int.MaxValue, customOptions.TryGetSInt32, Sint32Opt, d.GetOption, d.Options.GetExtension); - AssertOption(long.MaxValue, customOptions.TryGetSInt64, Sint64Opt, d.GetOption, d.Options.GetExtension); - AssertOption(uint.MaxValue, customOptions.TryGetFixed32, Fixed32Opt, d.GetOption, d.Options.GetExtension); - AssertOption(ulong.MaxValue, customOptions.TryGetFixed64, Fixed64Opt, d.GetOption, d.Options.GetExtension); - AssertOption(int.MaxValue, customOptions.TryGetSFixed32, Sfixed32Opt, d.GetOption, d.Options.GetExtension); - AssertOption(long.MaxValue, customOptions.TryGetSFixed64, Sfixed64Opt, d.GetOption, d.Options.GetExtension); + AssertOption(true, customOptions.TryGetBool, BoolOpt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(int.MaxValue, customOptions.TryGetInt32, Int32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(long.MaxValue, customOptions.TryGetInt64, Int64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(uint.MaxValue, customOptions.TryGetUInt32, Uint32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(ulong.MaxValue, customOptions.TryGetUInt64, Uint64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(int.MaxValue, customOptions.TryGetSInt32, Sint32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(long.MaxValue, customOptions.TryGetSInt64, Sint64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(uint.MaxValue, customOptions.TryGetFixed32, Fixed32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(ulong.MaxValue, customOptions.TryGetFixed64, Fixed64Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(int.MaxValue, customOptions.TryGetSFixed32, Sfixed32Opt, d.GetOption, d.GetOptions().GetExtension); + AssertOption(long.MaxValue, customOptions.TryGetSFixed64, Sfixed64Opt, d.GetOption, d.GetOptions().GetExtension); } [Test] @@ -195,10 +195,10 @@ public void AggregateOptions() { // Just two examples var messageDescriptor = AggregateMessage.Descriptor; - AssertOption(new Aggregate { I = 101, S = "MessageAnnotation" }, messageDescriptor.CustomOptions.TryGetMessage, Msgopt, messageDescriptor.GetOption, messageDescriptor.Options.GetExtension); + AssertOption(new Aggregate { I = 101, S = "MessageAnnotation" }, messageDescriptor.CustomOptions.TryGetMessage, Msgopt, messageDescriptor.GetOption, messageDescriptor.GetOptions().GetExtension); var fieldDescriptor = messageDescriptor.Fields["fieldname"]; - AssertOption(new Aggregate { S = "FieldAnnotation" }, fieldDescriptor.CustomOptions.TryGetMessage, Fieldopt, fieldDescriptor.GetOption, fieldDescriptor.Options.GetExtension); + AssertOption(new Aggregate { S = "FieldAnnotation" }, fieldDescriptor.CustomOptions.TryGetMessage, Fieldopt, fieldDescriptor.GetOption, fieldDescriptor.GetOptions().GetExtension); } [Test] @@ -222,8 +222,8 @@ public void MultipleImportOfSameFileWithExtension() var descriptor = UnittestIssue6936CReflection.Descriptor; var foo = Foo.Descriptor; var bar = Bar.Descriptor; - AssertOption("foo", foo.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, foo.GetOption, foo.Options.GetExtension); - AssertOption("bar", bar.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, bar.GetOption, bar.Options.GetExtension); + AssertOption("foo", foo.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, foo.GetOption, foo.GetOptions().GetExtension); + AssertOption("bar", bar.CustomOptions.TryGetString, UnittestIssue6936AExtensions.Opt, bar.GetOption, bar.GetOptions().GetExtension); } private void AssertOption(T expected, OptionFetcher customOptionFetcher, Extension extension, Func, T> getOptionFetcher, Func, T> extensionFetcher) where D : IExtendableMessage diff --git a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs index 795a95feeb54..f7e8b5b5f28d 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs @@ -128,21 +128,21 @@ public EnumValueDescriptor FindValueByName(string name) /// /// The (possibly empty) set of custom options for this enum. /// - [Obsolete("CustomOptions are obsolete. Use the Options property.")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// /// The EnumOptions, defined in descriptor.proto. - /// If the options message is not present (=there are no options), null is returned. + /// If the options message is not present (i.e. there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public EnumOptions Options => Proto.Options?.Clone(); + public EnumOptions GetOptions() => Proto.Options?.Clone(); /// /// Gets a single value enum option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -152,7 +152,7 @@ public T GetOption(Extension extension) /// /// Gets a repeated value enum option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs index 291ab8c58f8b..05097bd1da3d 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs @@ -73,21 +73,21 @@ public sealed class EnumValueDescriptor : DescriptorBase /// /// The (possibly empty) set of custom options for this enum value. /// - [Obsolete("CustomOptions are obsolete. Use the Options property")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// /// The EnumValueOptions, defined in descriptor.proto. - /// If the options message is not present (=there are no options), null is returned. + /// If the options message is not present (i.e. there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public EnumValueOptions Options => Proto.Options?.Clone(); + public EnumValueOptions GetOptions() => Proto.Options?.Clone(); /// /// Gets a single value enum value option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -97,7 +97,7 @@ public T GetOption(Extension extension) /// /// Gets a repeated value enum value option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs index 6ce606a3dfa2..e3068d803813 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -304,21 +304,21 @@ public MessageDescriptor ExtendeeType /// /// The (possibly empty) set of custom options for this field. /// - [Obsolete("CustomOptions are obsolete. Use the Options property.")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// /// The FieldOptions, defined in descriptor.proto. - /// If the options message is not present (=there are no options), null is returned. + /// If the options message is not present (i.e. there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public FieldOptions Options => Proto.Options?.Clone(); + public FieldOptions GetOptions() => Proto.Options?.Clone(); /// /// Gets a single value field option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -328,7 +328,7 @@ public T GetOption(Extension extension) /// /// Gets a repeated value field option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs index 9b298935da47..88e4a9de9621 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -547,21 +547,21 @@ public override string ToString() /// /// The (possibly empty) set of custom options for this file. /// - [Obsolete("CustomOptions are obsolete. Use the Options property.")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// /// The FileOptions, defined in descriptor.proto. - /// If the options message is not present (=there are no options), null is returned. + /// If the options message is not present (i.e. there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public FileOptions Options => Proto.Options?.Clone(); + public FileOptions GetOptions() => Proto.Options?.Clone(); /// /// Gets a single value file option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -571,7 +571,7 @@ public T GetOption(Extension extension) /// /// Gets a repeated value file option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index 9746bc89e464..7b5ab2fb48e7 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -287,21 +287,21 @@ internal bool IsExtensionsInitialized(IMessage message) /// /// The (possibly empty) set of custom options for this message. /// - [Obsolete("CustomOptions are obsolete. Use the Options property")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// /// The MessageOptions, defined in descriptor.proto. - /// If the options message is not present (=there are no options), null is returned. + /// If the options message is not present (i.e. there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public MessageOptions Options => Proto.Options?.Clone(); + public MessageOptions GetOptions() => Proto.Options?.Clone(); /// /// Gets a single value message option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -311,7 +311,7 @@ public T GetOption(Extension extension) /// /// Gets a repeated value message option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public Collections.RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs index b7c426d916f1..8e1503767bd7 100644 --- a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs @@ -73,21 +73,21 @@ public sealed class MethodDescriptor : DescriptorBase /// /// The (possibly empty) set of custom options for this method. /// - [Obsolete("CustomOptions are obsolete. Use the Options property.")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// /// The MethodOptions, defined in descriptor.proto. - /// If the options message is not present (=there are no options), null is returned. + /// If the options message is not present (i.e. there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public MethodOptions Options => Proto.Options?.Clone(); + public MethodOptions GetOptions() => Proto.Options?.Clone(); /// /// Gets a single value method option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -97,7 +97,7 @@ public T GetOption(Extension extension) /// /// Gets a repeated value method option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs index 302e66e23291..0df4f534b212 100644 --- a/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/OneofDescriptor.cs @@ -117,21 +117,21 @@ public MessageDescriptor ContainingType /// /// The (possibly empty) set of custom options for this oneof. /// - [Obsolete("CustomOptions are obsolete. Use the Options property.")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions method.")] public CustomOptions CustomOptions => new CustomOptions(proto.Options?._extensions?.ValuesByNumber); /// /// The OneofOptions, defined in descriptor.proto. - /// If the options message is not present (=there are no options), null is returned. + /// If the options message is not present (i.e. there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public OneofOptions Options => proto.Options?.Clone(); + public OneofOptions GetOptions() => proto.Options?.Clone(); /// /// Gets a single value oneof option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = proto.Options.GetExtension(extension); @@ -141,7 +141,7 @@ public T GetOption(Extension extension) /// /// Gets a repeated value oneof option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return proto.Options.GetExtension(extension).Clone(); diff --git a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs index f478db05ecc4..dab348b6f8ec 100644 --- a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs @@ -94,21 +94,21 @@ public MethodDescriptor FindMethodByName(String name) /// /// The (possibly empty) set of custom options for this service. /// - [Obsolete("CustomOptions are obsolete. Use the Options property.")] + [Obsolete("CustomOptions are obsolete. Use the GetOptions() method.")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options?._extensions?.ValuesByNumber); /// /// The ServiceOptions, defined in descriptor.proto. - /// If the options message is not present (=there are no options), null is returned. + /// If the options message is not present (i.e. there are no options), null is returned. /// Custom options can be retrieved as extensions of the returned message. /// NOTE: A defensive copy is created each time this property is retrieved. /// - public ServiceOptions Options => Proto.Options?.Clone(); + public ServiceOptions GetOptions() => Proto.Options?.Clone(); /// /// Gets a single value service option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); @@ -118,7 +118,7 @@ public T GetOption(Extension extension) /// /// Gets a repeated value service option for this descriptor /// - [Obsolete("GetOption is obsolete. Use the Options property.")] + [Obsolete("GetOption is obsolete. Use the GetOptions() method.")] public RepeatedField GetOption(RepeatedExtension extension) { return Proto.Options.GetExtension(extension).Clone();