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);
|
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]
|
[Test]
|
||||||
public void FieldDescriptor_GeneratedCode()
|
public void FieldDescriptor_GeneratedCode()
|
||||||
{
|
{
|
||||||
|
|
|
@ -242,7 +242,7 @@ namespace Google.Protobuf.Reflection
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns <c>true</c> if this field is a map field; <c>false</c> otherwise.
|
/// Returns <c>true</c> if this field is a map field; <c>false</c> otherwise.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsMap => FieldType == FieldType.Message && messageType.Proto.Options != null && messageType.Proto.Options.MapEntry;
|
public bool IsMap => FieldType == FieldType.Message && messageType.IsMapEntry;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns <c>true</c> if this field is a packed, repeated field; <c>false</c> otherwise.
|
/// 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>
|
/// </summary>
|
||||||
internal bool IsWrapperType => File.Package == "google.protobuf" && File.Name == "google/protobuf/wrappers.proto";
|
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>
|
/// <value>
|
||||||
/// If this is a nested type, get the outer descriptor, otherwise null.
|
/// If this is a nested type, get the outer descriptor, otherwise null.
|
||||||
/// </value>
|
/// </value>
|
||||||
|
|
Loading…
Reference in New Issue