Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

csharp generate identifiers for extensions #5246

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions src/google/protobuf/compiler/csharp/csharp_reflection_class.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
"/// <summary>Holder for reflection information generated from $file_name$</summary>\n"
Expand Down