aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/src/Google.Protobuf.Test/Reflection
diff options
context:
space:
mode:
authorGravatar Jon Skeet <jonskeet@google.com>2015-11-19 17:13:38 +0000
committerGravatar Jon Skeet <jonskeet@google.com>2015-11-22 16:25:44 +0000
commit72ec33676fd40ccfe719ace162fcf859ae9251bc (patch)
treea90f4be5e939a8a55175aa1d4e8e54c7f919feb1 /csharp/src/Google.Protobuf.Test/Reflection
parentd6202a9b8948d5a2d5436e3b35b175ed9b8a9fd1 (diff)
Tidy up reflection in advance of attempting to implement DynamicMessage.
There are corner cases where MessageDescriptor.{ClrType,Parser} will return null, and these are now documented. However, normally they *should* be implemented, even for descriptors of for dynamic messages. Ditto FieldDescriptor.Accessor. We'll still need a fair amount of work to implement dynamic messages, but this change means that the public API will be remain intact. Additionally, this change starts making use of C# 6 features in the files that it touches. This is far from exhaustive, and later PRs will have more. Generated code changes coming in the next commit.
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/Reflection')
-rw-r--r--csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs18
1 files changed, 6 insertions, 12 deletions
diff --git a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
index 51eff053..086a4e98 100644
--- a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
+++ b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
@@ -63,7 +63,7 @@ namespace Google.Protobuf.Reflection
Assert.AreEqual(UnittestImportProto3Reflection.Descriptor, file.Dependencies[0]);
MessageDescriptor messageType = TestAllTypes.Descriptor;
- Assert.AreSame(typeof(TestAllTypes), messageType.GeneratedType);
+ Assert.AreSame(typeof(TestAllTypes), messageType.ClrType);
Assert.AreSame(TestAllTypes.Parser, messageType.Parser);
Assert.AreEqual(messageType, file.MessageTypes[0]);
Assert.AreEqual(messageType, file.FindTypeByName<MessageDescriptor>("TestAllTypes"));
@@ -227,18 +227,12 @@ namespace Google.Protobuf.Reflection
}
[Test]
- public void ConstructionWithoutGeneratedCodeInfo()
+ public void MapEntryMessageDescriptor()
{
- var data = UnittestIssuesReflection.Descriptor.Proto.ToByteArray();
- var newDescriptor = Google.Protobuf.Reflection.FileDescriptor.InternalBuildGeneratedFileFrom(data, new Reflection.FileDescriptor[] { }, null);
-
- // We should still be able to get at a field...
- var messageDescriptor = newDescriptor.FindTypeByName<MessageDescriptor>("ItemField");
- var fieldDescriptor = messageDescriptor.FindFieldByName("item");
- // But there shouldn't be an accessor (or a generated type for the message, or parser)
- Assert.IsNull(fieldDescriptor.Accessor);
- Assert.IsNull(messageDescriptor.GeneratedType);
- Assert.IsNull(messageDescriptor.Parser);
+ var descriptor = MapWellKnownTypes.Descriptor.NestedTypes[0];
+ Assert.IsNull(descriptor.Parser);
+ Assert.IsNull(descriptor.ClrType);
+ Assert.IsNull(descriptor.Fields[1].Accessor);
}
// From TestFieldOrdering: