Skip to content

Commit

Permalink
C#: Fix discovery of oneof declarations in descriptor protos.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 627384633
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Apr 23, 2024
1 parent b618f67 commit b50ff60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,16 @@ public void NestedEnumValueComments()
Assert.AreEqual(" Zero value comment\n", value.Declaration.LeadingComments);
}

[Test]
public void OneofComments()
{
// CommentMessage doesn't have an enum, but we can use TestAllTypes.
var message = unitTestProto3Descriptor.FindTypeByName<MessageDescriptor>("TestAllTypes");
var oneof = message.Oneofs.Single(o => o.Name == "oneof_field");
Assert.NotNull(oneof.Declaration);
Assert.AreEqual(" For oneof test\n", oneof.Declaration.LeadingComments);
}

private static FileDescriptor LoadProtos()
{
var type = typeof(DescriptorDeclarationTest);
Expand Down
1 change: 1 addition & 0 deletions csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ internal override IReadOnlyList<DescriptorBase> GetNestedDescriptorListForField(
DescriptorProto.FieldFieldNumber => (IReadOnlyList<DescriptorBase>)fieldsInDeclarationOrder,
DescriptorProto.NestedTypeFieldNumber => (IReadOnlyList<DescriptorBase>)NestedTypes,
DescriptorProto.EnumTypeFieldNumber => (IReadOnlyList<DescriptorBase>)EnumTypes,
DescriptorProto.OneofDeclFieldNumber => (IReadOnlyList<DescriptorBase>)Oneofs,
_ => null,
};

Expand Down

0 comments on commit b50ff60

Please sign in to comment.