Introduce `MessageDescriptor.IsMapType` in C# reflection to make it easier to tell whether a given message was generated by protoc for a map field.
PiperOrigin-RevId: 628087118pull/16647/head
parent
9ea682d1ee
commit
047fc7673e
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -242,7 +242,7 @@ namespace Google.Protobuf.Reflection
|
|||
/// <summary>
|
||||
/// Returns <c>true</c> if this field is a map field; <c>false</c> otherwise.
|
||||
/// </summary>
|
||||
public bool IsMap => FieldType == FieldType.Message && messageType.Proto.Options != null && messageType.Proto.Options.MapEntry;
|
||||
public bool IsMap => FieldType == FieldType.Message && messageType.IsMapEntry;
|
||||
|
||||
/// <summary>
|
||||
/// Returns <c>true</c> if this field is a packed, repeated field; <c>false</c> otherwise.
|
||||
|
|
|
@ -202,6 +202,12 @@ namespace Google.Protobuf.Reflection
|
|||
/// </summary>
|
||||
internal bool IsWrapperType => File.Package == "google.protobuf" && File.Name == "google/protobuf/wrappers.proto";
|
||||
|
||||
/// <summary>
|
||||
/// Returns whether this message was synthetically-created to store key/value pairs in a
|
||||
/// map field.
|
||||
/// </summary>
|
||||
public bool IsMapEntry => Proto.Options?.MapEntry == true;
|
||||
|
||||
/// <value>
|
||||
/// If this is a nested type, get the outer descriptor, otherwise null.
|
||||
/// </value>
|
||||
|
|
Loading…
Reference in New Issue