aboutsummaryrefslogtreecommitdiff
path: root/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
diff options
context:
space:
mode:
authorJon Skeet <jonskeet@google.com>2015-07-22 19:57:29 +0100
committerJon Skeet <jonskeet@google.com>2015-07-22 20:13:38 +0100
commitc1c6b2d0d579d863c2ff3709a0053039801f5430 (patch)
tree67df2426209fb564b4a8504fafd1ceaf8481bfdb /csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
parent5e0cfc9a4796ab449e042098e914ace9a635c0b6 (diff)
downloadprotobuf-c1c6b2d0d579d863c2ff3709a0053039801f5430.tar.gz
protobuf-c1c6b2d0d579d863c2ff3709a0053039801f5430.tar.bz2
protobuf-c1c6b2d0d579d863c2ff3709a0053039801f5430.zip
Implemented Jan's suggestion of FieldCollection, replacing FieldAccessorCollection.
I think Jan was actually suggesting keeping both, but that feels redundant to me. The test diff is misleading here IMO, because I wouldn't expect real code using reflection to use several accessors one after another like this, unless it was within a loop. Evidence to the contrary would be welcome :) This change also incidentally goes part way to fixing the issue of the JSON formatter not writing out the fields in field number order - with this change, it does except for oneofs, which we can fix in a follow-up change. I haven't actually added a test with a message with fields deliberately out of order - I'm happy to do so though. It feels like it would make sense to be in google/src/protobuf, but it's not entirely clear what the rules of engagement are for adding new messages there. (unittest_proto3.proto?)
Diffstat (limited to 'csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs')
-rw-r--r--csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs7
1 files changed, 4 insertions, 3 deletions
diff --git a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
index f4128e08..5b6dc0fb 100644
--- a/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
+++ b/csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs
@@ -103,15 +103,16 @@ namespace Google.Protobuf.Reflection
Assert.AreEqual(UnittestProto3.Descriptor, nestedType.File);
Assert.AreEqual(messageType, nestedType.ContainingType);
- FieldDescriptor field = messageType.Fields[0];
+ FieldDescriptor field = messageType.Fields.InDeclarationOrder()[0];
Assert.AreEqual("single_int32", field.Name);
Assert.AreEqual(field, messageType.FindDescriptor<FieldDescriptor>("single_int32"));
Assert.Null(messageType.FindDescriptor<FieldDescriptor>("no_such_field"));
Assert.AreEqual(field, messageType.FindFieldByNumber(1));
Assert.Null(messageType.FindFieldByNumber(571283));
- for (int i = 0; i < messageType.Fields.Count; i++)
+ var fieldsInDeclarationOrder = messageType.Fields.InDeclarationOrder();
+ for (int i = 0; i < fieldsInDeclarationOrder.Count; i++)
{
- Assert.AreEqual(i, messageType.Fields[i].Index);
+ Assert.AreEqual(i, fieldsInDeclarationOrder[i].Index);
}
Assert.AreEqual(nestedType, messageType.NestedTypes[0]);