Skip to content

Commit b50ff60

Browse files
C#: Fix discovery of oneof declarations in descriptor protos.
PiperOrigin-RevId: 627384633
1 parent b618f67 commit b50ff60

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

csharp/src/Google.Protobuf.Test/Reflection/DescriptorDeclarationTest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ public void NestedEnumValueComments()
137137
Assert.AreEqual(" Zero value comment\n", value.Declaration.LeadingComments);
138138
}
139139

140+
[Test]
141+
public void OneofComments()
142+
{
143+
// CommentMessage doesn't have an enum, but we can use TestAllTypes.
144+
var message = unitTestProto3Descriptor.FindTypeByName<MessageDescriptor>("TestAllTypes");
145+
var oneof = message.Oneofs.Single(o => o.Name == "oneof_field");
146+
Assert.NotNull(oneof.Declaration);
147+
Assert.AreEqual(" For oneof test\n", oneof.Declaration.LeadingComments);
148+
}
149+
140150
private static FileDescriptor LoadProtos()
141151
{
142152
var type = typeof(DescriptorDeclarationTest);

csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ internal override IReadOnlyList<DescriptorBase> GetNestedDescriptorListForField(
119119
DescriptorProto.FieldFieldNumber => (IReadOnlyList<DescriptorBase>)fieldsInDeclarationOrder,
120120
DescriptorProto.NestedTypeFieldNumber => (IReadOnlyList<DescriptorBase>)NestedTypes,
121121
DescriptorProto.EnumTypeFieldNumber => (IReadOnlyList<DescriptorBase>)EnumTypes,
122+
DescriptorProto.OneofDeclFieldNumber => (IReadOnlyList<DescriptorBase>)Oneofs,
122123
_ => null,
123124
};
124125

0 commit comments

Comments
 (0)