From 05712c6791d959c73d059d255ec3ab316d8ab922 Mon Sep 17 00:00:00 2001 From: Sydney Acksman Date: Fri, 15 Mar 2019 21:28:59 -0500 Subject: [PATCH] Reapply custom option accessors from previous PR along with CustomOptions accessor deprecations --- .../Google.Protobuf.Test/Reflection/CustomOptionsTest.cs | 2 ++ csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs | 6 ++---- .../src/Google.Protobuf/Reflection/EnumValueDescriptor.cs | 6 ++---- csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs | 6 ++---- csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs | 6 ++---- csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs | 6 ++---- csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs | 6 ++---- csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs | 6 ++---- 8 files changed, 16 insertions(+), 28 deletions(-) diff --git a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs index ff4e9a7ffd..7aa2077778 100644 --- a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs +++ b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs @@ -41,6 +41,8 @@ using static UnitTest.Issues.TestProtos.ComplexOptionType2.Types; using static UnitTest.Issues.TestProtos.DummyMessageContainingEnum.Types; using static Google.Protobuf.Test.Reflection.CustomOptionNumber; +#pragma warning disable CS0618 + namespace Google.Protobuf.Test.Reflection { // Internal enum to allow us to use "using static" for convenience. diff --git a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs index 36a1d0a5ec..33be96198d 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs @@ -128,17 +128,16 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this enum. /// - //[Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use GetOption")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options._extensions?.ValuesByNumber); - /* // uncomment this in the full proto2 support PR /// /// Gets a single value enum option for this descriptor /// public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable clonable ? clonable.Clone() : value; + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; } /// @@ -148,6 +147,5 @@ namespace Google.Protobuf.Reflection { 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 99c989130c..3936aa4e26 100644 --- a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs @@ -73,17 +73,16 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this enum value. /// - //[Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use GetOption")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options._extensions?.ValuesByNumber); - /* // uncomment this in the full proto2 support PR /// /// Gets a single value enum option for this descriptor /// public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable clonable ? clonable.Clone() : value; + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; } /// @@ -93,7 +92,6 @@ namespace Google.Protobuf.Reflection { 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 5a2f7f3d8e..c06328f99c 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -277,17 +277,16 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this field. /// - //[Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use GetOption")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options._extensions?.ValuesByNumber); - /* // uncomment this in the full proto2 support PR /// /// Gets a single value enum option for this descriptor /// public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable clonable ? clonable.Clone() : value; + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; } /// @@ -297,7 +296,6 @@ namespace Google.Protobuf.Reflection { 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 9b20e3d22a..13266f725d 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -504,17 +504,16 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this file. /// - //[Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use GetOption")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options._extensions?.ValuesByNumber); - /* // uncomment this in the full proto2 support PR /// /// Gets a single value enum option for this descriptor /// public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable clonable ? clonable.Clone() : value; + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; } /// @@ -524,7 +523,6 @@ namespace Google.Protobuf.Reflection { 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 15bfbfadd0..4ca9e36989 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -243,17 +243,16 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this message. /// - //[Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use GetOption")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options._extensions?.ValuesByNumber); - /* // uncomment this in the full proto2 support PR /// /// Gets a single value enum option for this descriptor /// public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable clonable ? clonable.Clone() : value; + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; } /// @@ -263,7 +262,6 @@ namespace Google.Protobuf.Reflection { 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 1b37d9b172..c138576b32 100644 --- a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs @@ -73,17 +73,16 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this method. /// - //[Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use GetOption")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options._extensions?.ValuesByNumber); - /* // uncomment this in the full proto2 support PR /// /// Gets a single value enum option for this descriptor /// public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable clonable ? clonable.Clone() : value; + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; } /// @@ -93,7 +92,6 @@ namespace Google.Protobuf.Reflection { return Proto.Options.GetExtension(extension).Clone(); } - */ internal MethodDescriptor(MethodDescriptorProto proto, FileDescriptor file, ServiceDescriptor parent, int index) diff --git a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs index 54f4df7298..215aff5d44 100644 --- a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs @@ -94,17 +94,16 @@ namespace Google.Protobuf.Reflection /// /// The (possibly empty) set of custom options for this service. /// - //[Obsolete("CustomOptions are obsolete. Use GetOption")] + [Obsolete("CustomOptions are obsolete. Use GetOption")] public CustomOptions CustomOptions => new CustomOptions(Proto.Options._extensions?.ValuesByNumber); - /* // uncomment this in the full proto2 support PR /// /// Gets a single value enum option for this descriptor /// public T GetOption(Extension extension) { var value = Proto.Options.GetExtension(extension); - return value is IDeepCloneable clonable ? clonable.Clone() : value; + return value is IDeepCloneable ? (value as IDeepCloneable).Clone() : value; } /// @@ -114,7 +113,6 @@ namespace Google.Protobuf.Reflection { return Proto.Options.GetExtension(extension).Clone(); } - */ internal void CrossLink() {