diff --git a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs index 68b4d6af7cf8b..9469df7239b28 100644 --- a/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs +++ b/csharp/src/Google.Protobuf.Test/Reflection/CustomOptionsTest.cs @@ -121,7 +121,7 @@ public void SimpleIntegerTest() var options = CustomOptions.Empty; options = options.ReadOrSkipUnknownField(input); - + int intValue; Assert.True(options.TryGetInt32(1, out intValue)); Assert.AreEqual(1234567, intValue); @@ -147,7 +147,7 @@ public void SimpleStringTest() var options = CustomOptions.Empty; options = options.ReadOrSkipUnknownField(input); - + string stringValue; Assert.True(options.TryGetString(1, out stringValue)); Assert.AreEqual("value", stringValue); @@ -195,7 +195,7 @@ public void OptionLocations() var messageOptions = TestMessageWithCustomOptions.Descriptor.CustomOptions; AssertOption(-56, messageOptions.TryGetInt32, MessageOpt1); - var fieldOptions = TestMessageWithCustomOptions.Descriptor.Fields["field1"] .CustomOptions; + var fieldOptions = TestMessageWithCustomOptions.Descriptor.Fields["field1"].CustomOptions; AssertOption(8765432109UL, fieldOptions.TryGetFixed64, FieldOpt1); var oneofOptions = TestMessageWithCustomOptions.Descriptor.Oneofs[0].CustomOptions; diff --git a/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc b/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc index 5ddd616e10f59..47d49c39daca1 100644 --- a/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc +++ b/src/google/protobuf/compiler/csharp/csharp_reflection_class.cc @@ -122,6 +122,21 @@ void ReflectionClassGenerator::WriteIntroduction(io::Printer* printer) { printer->Indent(); printer->Print("\n"); } + + printer->Print("public static class Extensions {\n"); + printer->Indent(); + for (int i = 0; i < file_->extension_count(); ++i) { + const FieldDescriptor* extension_field = file_->extension(i); + string var_name = GetFieldConstantName(extension_field); + + printer->Print("public const int $var_name$ = $extension_id$;\n", + "var_name", var_name, + "extension_id", SimpleItoa(extension_field->number())); + } + printer->Outdent(); + printer->Print("}\n"); + + printer->Print( "/// Holder for reflection information generated from $file_name$\n"