diff --git a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs index 4bd857aacb..f908b2815c 100644 --- a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs +++ b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs @@ -204,6 +204,14 @@ namespace Google.Protobuf.Reflection TestDescriptorToProto(messageType.ToProto, messageType.Proto); } + [Test] + public void MessageDescriptor_IsMapEntry() + { + var testMapMessage = TestMap.Descriptor; + Assert.False(testMapMessage.IsMapEntry); + Assert.True(testMapMessage.Fields[1].MessageType.IsMapEntry); + } + [Test] public void FieldDescriptor_GeneratedCode() { diff --git a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs index 9d41930838..d9bf6b373f 100644 --- a/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FieldDescriptor.cs @@ -242,7 +242,7 @@ namespace Google.Protobuf.Reflection /// /// Returns true if this field is a map field; false otherwise. /// - public bool IsMap => FieldType == FieldType.Message && messageType.Proto.Options != null && messageType.Proto.Options.MapEntry; + public bool IsMap => FieldType == FieldType.Message && messageType.IsMapEntry; /// /// Returns true if this field is a packed, repeated field; false otherwise. diff --git a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs index ead4676a5c..b4b69ad6e3 100644 --- a/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs @@ -202,6 +202,12 @@ namespace Google.Protobuf.Reflection /// internal bool IsWrapperType => File.Package == "google.protobuf" && File.Name == "google/protobuf/wrappers.proto"; + /// + /// Returns whether this message was synthetically-created to store key/value pairs in a + /// map field. + /// + public bool IsMapEntry => Proto.Options?.MapEntry == true; + /// /// If this is a nested type, get the outer descriptor, otherwise null. ///