diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto2.cs b/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto2.cs index a2577dfc0f..04e1dc41ad 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto2.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/TestMessagesProto2.cs @@ -227,6 +227,7 @@ namespace ProtobufTestMessages.Proto2 { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestAllTypesProto2()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; private int _hasBits0; private int _hasBits1; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] @@ -3703,6 +3704,7 @@ namespace ProtobufTestMessages.Proto2 { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MessageSetCorrect()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } diff --git a/csharp/src/Google.Protobuf.Test/TestProtos/Unittest.cs b/csharp/src/Google.Protobuf.Test/TestProtos/Unittest.cs index 1043d738c8..5d7339f150 100644 --- a/csharp/src/Google.Protobuf.Test/TestProtos/Unittest.cs +++ b/csharp/src/Google.Protobuf.Test/TestProtos/Unittest.cs @@ -5139,6 +5139,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestAllExtensions()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -5913,6 +5914,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestGroupExtension()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -8483,6 +8485,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestEmptyMessageWithExtensions()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -8623,6 +8626,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestMultipleExtensionRanges()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -11932,6 +11936,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestFieldOrderings()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; private int _hasBits0; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -19245,6 +19250,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestPackedExtensions()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -19385,6 +19391,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestUnpackedExtensions()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -20287,6 +20294,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestParsingMerge()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -22563,6 +22571,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestHugeFieldNumbers()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; private int _hasBits0; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -23417,6 +23426,7 @@ namespace Google.Protobuf.TestProtos.Proto2 { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TestExtensionInsideTable()); private pb::UnknownFieldSet _unknownFields; private pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; private int _hasBits0; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } diff --git a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs index 20bd4b65d6..8656cb5f87 100644 --- a/csharp/src/Google.Protobuf/Reflection/Descriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/Descriptor.cs @@ -1591,6 +1591,7 @@ namespace Google.Protobuf.Reflection { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ExtensionRangeOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -3819,6 +3820,7 @@ namespace Google.Protobuf.Reflection { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FileOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; private int _hasBits0; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -4916,6 +4918,7 @@ namespace Google.Protobuf.Reflection { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MessageOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; private int _hasBits0; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -5299,6 +5302,7 @@ namespace Google.Protobuf.Reflection { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new FieldOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; private int _hasBits0; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -5805,6 +5809,7 @@ namespace Google.Protobuf.Reflection { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new OneofOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -5968,6 +5973,7 @@ namespace Google.Protobuf.Reflection { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; private int _hasBits0; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -6225,6 +6231,7 @@ namespace Google.Protobuf.Reflection { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new EnumValueOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; private int _hasBits0; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -6437,6 +6444,7 @@ namespace Google.Protobuf.Reflection { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ServiceOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; private int _hasBits0; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } @@ -6649,6 +6657,7 @@ namespace Google.Protobuf.Reflection { private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new MethodOptions()); private pb::UnknownFieldSet _unknownFields; internal pb::ExtensionSet _extensions; + private pb::ExtensionSet _Extensions => _extensions; private int _hasBits0; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public static pb::MessageParser Parser { get { return _parser; } } diff --git a/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs b/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs index e92efd52e9..8879c5543b 100644 --- a/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs +++ b/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs @@ -312,14 +312,19 @@ namespace Google.Protobuf.Reflection { public Func CreateIsInitializedCaller() { - var field = typeof(T1).GetTypeInfo().GetDeclaredField("_extensions"); + var prop = typeof(T1).GetTypeInfo().GetDeclaredProperty("_Extensions"); +#if NET35 + var getFunc = (Func>)prop.GetGetMethod(true).CreateDelegate(typeof(Func>)); +#else + var getFunc = (Func>)prop.GetMethod.CreateDelegate(typeof(Func>)); +#endif var initializedFunc = (Func, bool>) typeof(ExtensionSet) .GetTypeInfo() .GetDeclaredMethod("IsInitialized") .CreateDelegate(typeof(Func, bool>)); return (m) => { - var set = field.GetValue(m) as ExtensionSet; + var set = getFunc((T1)m); return set == null || initializedFunc(set); }; } diff --git a/src/google/protobuf/compiler/csharp/csharp_message.cc b/src/google/protobuf/compiler/csharp/csharp_message.cc index 73cc2a4600..e4b87dfbbe 100644 --- a/src/google/protobuf/compiler/csharp/csharp_message.cc +++ b/src/google/protobuf/compiler/csharp/csharp_message.cc @@ -149,6 +149,8 @@ void MessageGenerator::Generate(io::Printer* printer) { } else { printer->Print(vars, "private pb::ExtensionSet<$class_name$> _extensions;\n"); } + + printer->Print(vars, "private pb::ExtensionSet<$class_name$> _Extensions => _extensions;\n"); // a read-only property for fast retrieval of the set in IsInitialized } for (int i = 0; i < has_bit_field_count_; i++) {