Reapply custom option accessors from previous PR along with CustomOptions accessor deprecations
diff --git a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs
index ff4e9a7..7aa2077 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.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 36a1d0a..33be961 100644
--- a/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/EnumDescriptor.cs
@@ -128,17 +128,16 @@
/// <summary>
/// The (possibly empty) set of custom options for this enum.
/// </summary>
- //[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
/// <summary>
/// Gets a single value enum option for this descriptor
/// </summary>
public T GetOption<T>(Extension<EnumOptions, T> extension)
{
var value = Proto.Options.GetExtension(extension);
- return value is IDeepCloneable<T> clonable ? clonable.Clone() : value;
+ return value is IDeepCloneable<T> ? (value as IDeepCloneable<T>).Clone() : value;
}
/// <summary>
@@ -148,6 +147,5 @@
{
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 99c9891..3936aa4 100644
--- a/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/EnumValueDescriptor.cs
@@ -73,17 +73,16 @@
/// <summary>
/// The (possibly empty) set of custom options for this enum value.
/// </summary>
- //[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
/// <summary>
/// Gets a single value enum option for this descriptor
/// </summary>
public T GetOption<T>(Extension<EnumValueOptions, T> extension)
{
var value = Proto.Options.GetExtension(extension);
- return value is IDeepCloneable<T> clonable ? clonable.Clone() : value;
+ return value is IDeepCloneable<T> ? (value as IDeepCloneable<T>).Clone() : value;
}
/// <summary>
@@ -93,7 +92,6 @@
{
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 5a2f7f3..c06328f 100644
--- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs
@@ -277,17 +277,16 @@
/// <summary>
/// The (possibly empty) set of custom options for this field.
/// </summary>
- //[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
/// <summary>
/// Gets a single value enum option for this descriptor
/// </summary>
public T GetOption<T>(Extension<FieldOptions, T> extension)
{
var value = Proto.Options.GetExtension(extension);
- return value is IDeepCloneable<T> clonable ? clonable.Clone() : value;
+ return value is IDeepCloneable<T> ? (value as IDeepCloneable<T>).Clone() : value;
}
/// <summary>
@@ -297,7 +296,6 @@
{
return Proto.Options.GetExtension(extension).Clone();
}
- */
/// <summary>
/// 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 9b20e3d..13266f7 100644
--- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs
@@ -504,17 +504,16 @@
/// <summary>
/// The (possibly empty) set of custom options for this file.
/// </summary>
- //[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
/// <summary>
/// Gets a single value enum option for this descriptor
/// </summary>
public T GetOption<T>(Extension<FileOptions, T> extension)
{
var value = Proto.Options.GetExtension(extension);
- return value is IDeepCloneable<T> clonable ? clonable.Clone() : value;
+ return value is IDeepCloneable<T> ? (value as IDeepCloneable<T>).Clone() : value;
}
/// <summary>
@@ -524,7 +523,6 @@
{
return Proto.Options.GetExtension(extension).Clone();
}
- */
/// <summary>
/// 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 15bfbfa..4ca9e36 100644
--- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
@@ -243,17 +243,16 @@
/// <summary>
/// The (possibly empty) set of custom options for this message.
/// </summary>
- //[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
/// <summary>
/// Gets a single value enum option for this descriptor
/// </summary>
public T GetOption<T>(Extension<MessageOptions, T> extension)
{
var value = Proto.Options.GetExtension(extension);
- return value is IDeepCloneable<T> clonable ? clonable.Clone() : value;
+ return value is IDeepCloneable<T> ? (value as IDeepCloneable<T>).Clone() : value;
}
/// <summary>
@@ -263,7 +262,6 @@
{
return Proto.Options.GetExtension(extension).Clone();
}
- */
/// <summary>
/// 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 1b37d9b..c138576 100644
--- a/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/MethodDescriptor.cs
@@ -73,17 +73,16 @@
/// <summary>
/// The (possibly empty) set of custom options for this method.
/// </summary>
- //[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
/// <summary>
/// Gets a single value enum option for this descriptor
/// </summary>
public T GetOption<T>(Extension<MethodOptions, T> extension)
{
var value = Proto.Options.GetExtension(extension);
- return value is IDeepCloneable<T> clonable ? clonable.Clone() : value;
+ return value is IDeepCloneable<T> ? (value as IDeepCloneable<T>).Clone() : value;
}
/// <summary>
@@ -93,7 +92,6 @@
{
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 54f4df7..215aff5 100644
--- a/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs
+++ b/csharp/src/Google.Protobuf/Reflection/ServiceDescriptor.cs
@@ -94,17 +94,16 @@
/// <summary>
/// The (possibly empty) set of custom options for this service.
/// </summary>
- //[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
/// <summary>
/// Gets a single value enum option for this descriptor
/// </summary>
public T GetOption<T>(Extension<ServiceOptions, T> extension)
{
var value = Proto.Options.GetExtension(extension);
- return value is IDeepCloneable<T> clonable ? clonable.Clone() : value;
+ return value is IDeepCloneable<T> ? (value as IDeepCloneable<T>).Clone() : value;
}
/// <summary>
@@ -114,7 +113,6 @@
{
return Proto.Options.GetExtension(extension).Clone();
}
- */
internal void CrossLink()
{