فهرست منبع

Fix trivial bug in field orderings.

(Shows the benefit of unit testing even code "too simple to fail"...)
Jon Skeet 10 سال پیش
والد
کامیت
fd02e45b2a

+ 13 - 0
csharp/src/Google.Protobuf.Test/Reflection/DescriptorsTest.cs

@@ -238,5 +238,18 @@ namespace Google.Protobuf.Reflection
             Assert.IsNull(fieldDescriptor.Accessor);
             Assert.IsNull(messageDescriptor.GeneratedType);
         }
+
+        // From TestFieldOrdering:
+        // string my_string = 11;
+        // int64 my_int = 1;
+        // float my_float = 101;
+        // NestedMessage single_nested_message = 200;
+        [Test]
+        public void FieldListOrderings()
+        { 
+            var fields = TestFieldOrderings.Descriptor.Fields;
+            Assert.AreEqual(new[] { 11, 1, 101, 200 }, fields.InDeclarationOrder().Select(x => x.FieldNumber));
+            Assert.AreEqual(new[] { 1, 11, 101, 200 }, fields.InFieldNumberOrder().Select(x => x.FieldNumber));
+        }
     }
 }

+ 1 - 1
csharp/src/Google.Protobuf/Reflection/MessageDescriptor.cs

@@ -250,7 +250,7 @@ namespace Google.Protobuf.Reflection
             /// </value>
             public IList<FieldDescriptor> InFieldNumberOrder()
             {
-                return messageDescriptor.fieldsInDeclarationOrder;
+                return messageDescriptor.fieldsInNumberOrder;
             }
 
             /// <summary>