From 1711999078ca1d435de3958bf963e95a742e972f Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Thu, 30 Aug 2018 14:53:06 +0100 Subject: Provide simple access to descriptor declarations in C# This is primarily for access to comments, which would be expected to be available in a protoc plugin. The implementation has two fiddly aspects: - We use a Lazy to avoid building the map before cross-linking. An alternative would be to crosslink at the end of the constructor, and remove the calls to CrossLink elsewhere. This would be generally better IMO, but deviate from the Java code. - The casts to IReadOnlyList are unfortunate. They'll always work, because these lists are always ReadOnlyCollection for a descriptor type... but we can't use IList as that's not covariant, and it's annoyingly fiddly to change the field to be of type ReadOnlyCollection. --- .../src/Google.Protobuf/Reflection/MessageDescriptor.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs') diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index dbb6768b..03fd63ce 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -115,6 +115,21 @@ namespace Google.Protobuf.Reflection /// public override string Name => Proto.Name; + internal override IReadOnlyList GetNestedDescriptorListForField(int fieldNumber) + { + switch (fieldNumber) + { + case DescriptorProto.FieldFieldNumber: + return (IReadOnlyList) fieldsInDeclarationOrder; + case DescriptorProto.NestedTypeFieldNumber: + return (IReadOnlyList) NestedTypes; + case DescriptorProto.EnumTypeFieldNumber: + return (IReadOnlyList) EnumTypes; + default: + return null; + } + } + internal DescriptorProto Proto { get; } /// -- cgit v1.2.3