本文整理汇总了C#中IMessage.GetRepeatedFieldCount方法的典型用法代码示例。如果您正苦于以下问题:C# IMessage.GetRepeatedFieldCount方法的具体用法?C# IMessage.GetRepeatedFieldCount怎么用?C# IMessage.GetRepeatedFieldCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMessage
的用法示例。
在下文中一共展示了IMessage.GetRepeatedFieldCount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertPackedFieldsSetViaReflection
public void AssertPackedFieldsSetViaReflection(IMessage message)
{
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_int32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_int64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_uint32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_uint64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_sint32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_sint64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_fixed32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_fixed64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_sfixed32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_sfixed64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_float")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_double")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_bool")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("packed_enum")));
Assert.AreEqual(601, message[f("packed_int32"), 0]);
Assert.AreEqual(602L, message[f("packed_int64"), 0]);
Assert.AreEqual(603u, message[f("packed_uint32"), 0]);
Assert.AreEqual(604uL, message[f("packed_uint64"), 0]);
Assert.AreEqual(605, message[f("packed_sint32"), 0]);
Assert.AreEqual(606L, message[f("packed_sint64"), 0]);
Assert.AreEqual(607u, message[f("packed_fixed32"), 0]);
Assert.AreEqual(608uL, message[f("packed_fixed64"), 0]);
Assert.AreEqual(609, message[f("packed_sfixed32"), 0]);
Assert.AreEqual(610L, message[f("packed_sfixed64"), 0]);
Assert.AreEqual(611F, message[f("packed_float"), 0]);
Assert.AreEqual(612D, message[f("packed_double"), 0]);
Assert.AreEqual(true, message[f("packed_bool"), 0]);
Assert.AreEqual(foreignBar, message[f("packed_enum"), 0]);
Assert.AreEqual(701, message[f("packed_int32"), 1]);
Assert.AreEqual(702L, message[f("packed_int64"), 1]);
Assert.AreEqual(703u, message[f("packed_uint32"), 1]);
Assert.AreEqual(704uL, message[f("packed_uint64"), 1]);
Assert.AreEqual(705, message[f("packed_sint32"), 1]);
Assert.AreEqual(706L, message[f("packed_sint64"), 1]);
Assert.AreEqual(707u, message[f("packed_fixed32"), 1]);
Assert.AreEqual(708uL, message[f("packed_fixed64"), 1]);
Assert.AreEqual(709, message[f("packed_sfixed32"), 1]);
Assert.AreEqual(710L, message[f("packed_sfixed64"), 1]);
Assert.AreEqual(711F, message[f("packed_float"), 1]);
Assert.AreEqual(712D, message[f("packed_double"), 1]);
Assert.AreEqual(false, message[f("packed_bool"), 1]);
Assert.AreEqual(foreignBaz, message[f("packed_enum"), 1]);
}
示例2: AssertClearViaReflection
/// <summary>
/// Assert that all fields of the message are cleared, and that
/// getting the fields returns their default values, using the reflection interface.
/// </summary>
public void AssertClearViaReflection(IMessage message)
{
// has_blah() should initially be false for all optional fields.
Assert.IsFalse(message.HasField(f("optional_int32")));
Assert.IsFalse(message.HasField(f("optional_int64")));
Assert.IsFalse(message.HasField(f("optional_uint32")));
Assert.IsFalse(message.HasField(f("optional_uint64")));
Assert.IsFalse(message.HasField(f("optional_sint32")));
Assert.IsFalse(message.HasField(f("optional_sint64")));
Assert.IsFalse(message.HasField(f("optional_fixed32")));
Assert.IsFalse(message.HasField(f("optional_fixed64")));
Assert.IsFalse(message.HasField(f("optional_sfixed32")));
Assert.IsFalse(message.HasField(f("optional_sfixed64")));
Assert.IsFalse(message.HasField(f("optional_float")));
Assert.IsFalse(message.HasField(f("optional_double")));
Assert.IsFalse(message.HasField(f("optional_bool")));
Assert.IsFalse(message.HasField(f("optional_string")));
Assert.IsFalse(message.HasField(f("optional_bytes")));
Assert.IsFalse(message.HasField(f("optionalgroup")));
Assert.IsFalse(message.HasField(f("optional_nested_message")));
Assert.IsFalse(message.HasField(f("optional_foreign_message")));
Assert.IsFalse(message.HasField(f("optional_import_message")));
Assert.IsFalse(message.HasField(f("optional_nested_enum")));
Assert.IsFalse(message.HasField(f("optional_foreign_enum")));
Assert.IsFalse(message.HasField(f("optional_import_enum")));
Assert.IsFalse(message.HasField(f("optional_string_piece")));
Assert.IsFalse(message.HasField(f("optional_cord")));
// Optional fields without defaults are set to zero or something like it.
Assert.AreEqual(0, message[f("optional_int32")]);
Assert.AreEqual(0L, message[f("optional_int64")]);
Assert.AreEqual(0U, message[f("optional_uint32")]);
Assert.AreEqual(0UL, message[f("optional_uint64")]);
Assert.AreEqual(0, message[f("optional_sint32")]);
Assert.AreEqual(0L, message[f("optional_sint64")]);
Assert.AreEqual(0U, message[f("optional_fixed32")]);
Assert.AreEqual(0UL, message[f("optional_fixed64")]);
Assert.AreEqual(0, message[f("optional_sfixed32")]);
Assert.AreEqual(0L, message[f("optional_sfixed64")]);
Assert.AreEqual(0F, message[f("optional_float")]);
Assert.AreEqual(0D, message[f("optional_double")]);
Assert.AreEqual(false, message[f("optional_bool")]);
Assert.AreEqual("", message[f("optional_string")]);
Assert.AreEqual(ByteString.Empty, message[f("optional_bytes")]);
// Embedded messages should also be clear.
Assert.IsFalse(((IMessage) message[f("optionalgroup")]).HasField(groupA));
Assert.IsFalse(((IMessage) message[f("optional_nested_message")])
.HasField(nestedB));
Assert.IsFalse(((IMessage) message[f("optional_foreign_message")])
.HasField(foreignC));
Assert.IsFalse(((IMessage) message[f("optional_import_message")])
.HasField(importD));
Assert.AreEqual(0, ((IMessage) message[f("optionalgroup")])[groupA]);
Assert.AreEqual(0, ((IMessage) message[f("optional_nested_message")])[nestedB]);
Assert.AreEqual(0, ((IMessage) message[f("optional_foreign_message")])[foreignC]);
Assert.AreEqual(0, ((IMessage) message[f("optional_import_message")])[importD]);
// Enums without defaults are set to the first value in the enum.
Assert.AreEqual(nestedFoo, message[f("optional_nested_enum")]);
Assert.AreEqual(foreignFoo, message[f("optional_foreign_enum")]);
Assert.AreEqual(importFoo, message[f("optional_import_enum")]);
Assert.AreEqual("", message[f("optional_string_piece")]);
Assert.AreEqual("", message[f("optional_cord")]);
// Repeated fields are empty.
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_int32")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_int64")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_uint32")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_uint64")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_sint32")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_sint64")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_fixed32")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_fixed64")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_sfixed32")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_sfixed64")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_float")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_double")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_bool")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_string")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_bytes")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeatedgroup")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_nested_message")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_foreign_message")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_import_message")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_nested_enum")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_foreign_enum")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_import_enum")));
Assert.AreEqual(0, message.GetRepeatedFieldCount(f("repeated_string_piece")));
//.........这里部分代码省略.........
示例3: AssertRepeatedFieldsModifiedViaReflection
// ---------------------------------------------------------------
internal void AssertRepeatedFieldsModifiedViaReflection(IMessage message)
{
// ModifyRepeatedFields only sets the second repeated element of each
// field. In addition to verifying this, we also verify that the first
// element and size were *not* modified.
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_int32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_int64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_uint32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_uint64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sint32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sint64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_fixed32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_fixed64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sfixed32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sfixed64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_float")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_double")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_bool")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_string")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_bytes")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeatedgroup")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_nested_message")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_foreign_message")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_import_message")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_nested_enum")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_foreign_enum")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_import_enum")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_string_piece")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_cord")));
Assert.AreEqual(201, message[f("repeated_int32"), 0]);
Assert.AreEqual(202L, message[f("repeated_int64"), 0]);
Assert.AreEqual(203U, message[f("repeated_uint32"), 0]);
Assert.AreEqual(204UL, message[f("repeated_uint64"), 0]);
Assert.AreEqual(205, message[f("repeated_sint32"), 0]);
Assert.AreEqual(206L, message[f("repeated_sint64"), 0]);
Assert.AreEqual(207U, message[f("repeated_fixed32"), 0]);
Assert.AreEqual(208UL, message[f("repeated_fixed64"), 0]);
Assert.AreEqual(209, message[f("repeated_sfixed32"), 0]);
Assert.AreEqual(210L, message[f("repeated_sfixed64"), 0]);
Assert.AreEqual(211F, message[f("repeated_float"), 0]);
Assert.AreEqual(212D, message[f("repeated_double"), 0]);
Assert.AreEqual(true, message[f("repeated_bool"), 0]);
Assert.AreEqual("215", message[f("repeated_string"), 0]);
Assert.AreEqual(TestUtil.ToBytes("216"), message[f("repeated_bytes"), 0]);
Assert.AreEqual(217, ((IMessage) message[f("repeatedgroup"), 0])[repeatedGroupA]);
Assert.AreEqual(218, ((IMessage) message[f("repeated_nested_message"), 0])[nestedB]);
Assert.AreEqual(219, ((IMessage) message[f("repeated_foreign_message"), 0])[foreignC]);
Assert.AreEqual(220, ((IMessage) message[f("repeated_import_message"), 0])[importD]);
Assert.AreEqual(nestedBar, message[f("repeated_nested_enum"), 0]);
Assert.AreEqual(foreignBar, message[f("repeated_foreign_enum"), 0]);
Assert.AreEqual(importBar, message[f("repeated_import_enum"), 0]);
Assert.AreEqual("224", message[f("repeated_string_piece"), 0]);
Assert.AreEqual("225", message[f("repeated_cord"), 0]);
Assert.AreEqual(501, message[f("repeated_int32"), 1]);
Assert.AreEqual(502L, message[f("repeated_int64"), 1]);
Assert.AreEqual(503U, message[f("repeated_uint32"), 1]);
Assert.AreEqual(504UL, message[f("repeated_uint64"), 1]);
Assert.AreEqual(505, message[f("repeated_sint32"), 1]);
Assert.AreEqual(506L, message[f("repeated_sint64"), 1]);
Assert.AreEqual(507U, message[f("repeated_fixed32"), 1]);
Assert.AreEqual(508UL, message[f("repeated_fixed64"), 1]);
Assert.AreEqual(509, message[f("repeated_sfixed32"), 1]);
Assert.AreEqual(510L, message[f("repeated_sfixed64"), 1]);
Assert.AreEqual(511F, message[f("repeated_float"), 1]);
Assert.AreEqual(512D, message[f("repeated_double"), 1]);
Assert.AreEqual(true, message[f("repeated_bool"), 1]);
Assert.AreEqual("515", message[f("repeated_string"), 1]);
Assert.AreEqual(TestUtil.ToBytes("516"), message[f("repeated_bytes"), 1]);
Assert.AreEqual(517, ((IMessage) message[f("repeatedgroup"), 1])[repeatedGroupA]);
Assert.AreEqual(518, ((IMessage) message[f("repeated_nested_message"), 1])[nestedB]);
Assert.AreEqual(519, ((IMessage) message[f("repeated_foreign_message"), 1])[foreignC]);
Assert.AreEqual(520, ((IMessage) message[f("repeated_import_message"), 1])[importD]);
Assert.AreEqual(nestedFoo, message[f("repeated_nested_enum"), 1]);
Assert.AreEqual(foreignFoo, message[f("repeated_foreign_enum"), 1]);
Assert.AreEqual(importFoo, message[f("repeated_import_enum"), 1]);
Assert.AreEqual("524", message[f("repeated_string_piece"), 1]);
Assert.AreEqual("525", message[f("repeated_cord"), 1]);
}
示例4: AssertAllFieldsSetViaReflection
// -------------------------------------------------------------------
/// <summary>
/// Asserts that all fields of the specified message are set to the values
/// assigned by SetAllFields, using the IMessage reflection interface.
/// </summary>
public void AssertAllFieldsSetViaReflection(IMessage message)
{
Assert.IsTrue(message.HasField(f("optional_int32")));
Assert.IsTrue(message.HasField(f("optional_int64")));
Assert.IsTrue(message.HasField(f("optional_uint32")));
Assert.IsTrue(message.HasField(f("optional_uint64")));
Assert.IsTrue(message.HasField(f("optional_sint32")));
Assert.IsTrue(message.HasField(f("optional_sint64")));
Assert.IsTrue(message.HasField(f("optional_fixed32")));
Assert.IsTrue(message.HasField(f("optional_fixed64")));
Assert.IsTrue(message.HasField(f("optional_sfixed32")));
Assert.IsTrue(message.HasField(f("optional_sfixed64")));
Assert.IsTrue(message.HasField(f("optional_float")));
Assert.IsTrue(message.HasField(f("optional_double")));
Assert.IsTrue(message.HasField(f("optional_bool")));
Assert.IsTrue(message.HasField(f("optional_string")));
Assert.IsTrue(message.HasField(f("optional_bytes")));
Assert.IsTrue(message.HasField(f("optionalgroup")));
Assert.IsTrue(message.HasField(f("optional_nested_message")));
Assert.IsTrue(message.HasField(f("optional_foreign_message")));
Assert.IsTrue(message.HasField(f("optional_import_message")));
Assert.IsTrue(((IMessage) message[f("optionalgroup")]).HasField(groupA));
Assert.IsTrue(((IMessage) message[f("optional_nested_message")]).HasField(nestedB));
Assert.IsTrue(((IMessage) message[f("optional_foreign_message")]).HasField(foreignC));
Assert.IsTrue(((IMessage) message[f("optional_import_message")]).HasField(importD));
Assert.IsTrue(message.HasField(f("optional_nested_enum")));
Assert.IsTrue(message.HasField(f("optional_foreign_enum")));
Assert.IsTrue(message.HasField(f("optional_import_enum")));
Assert.IsTrue(message.HasField(f("optional_string_piece")));
Assert.IsTrue(message.HasField(f("optional_cord")));
Assert.AreEqual(101, message[f("optional_int32")]);
Assert.AreEqual(102L, message[f("optional_int64")]);
Assert.AreEqual(103u, message[f("optional_uint32")]);
Assert.AreEqual(104UL, message[f("optional_uint64")]);
Assert.AreEqual(105, message[f("optional_sint32")]);
Assert.AreEqual(106L, message[f("optional_sint64")]);
Assert.AreEqual(107U, message[f("optional_fixed32")]);
Assert.AreEqual(108UL, message[f("optional_fixed64")]);
Assert.AreEqual(109, message[f("optional_sfixed32")]);
Assert.AreEqual(110L, message[f("optional_sfixed64")]);
Assert.AreEqual(111F, message[f("optional_float")]);
Assert.AreEqual(112D, message[f("optional_double")]);
Assert.AreEqual(true, message[f("optional_bool")]);
Assert.AreEqual("115", message[f("optional_string")]);
Assert.AreEqual(TestUtil.ToBytes("116"), message[f("optional_bytes")]);
Assert.AreEqual(117, ((IMessage) message[f("optionalgroup")])[groupA]);
Assert.AreEqual(118, ((IMessage) message[f("optional_nested_message")])[nestedB]);
Assert.AreEqual(119, ((IMessage) message[f("optional_foreign_message")])[foreignC]);
Assert.AreEqual(120, ((IMessage) message[f("optional_import_message")])[importD]);
Assert.AreEqual(nestedBaz, message[f("optional_nested_enum")]);
Assert.AreEqual(foreignBaz, message[f("optional_foreign_enum")]);
Assert.AreEqual(importBaz, message[f("optional_import_enum")]);
Assert.AreEqual("124", message[f("optional_string_piece")]);
Assert.AreEqual("125", message[f("optional_cord")]);
// -----------------------------------------------------------------
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_int32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_int64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_uint32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_uint64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sint32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sint64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_fixed32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_fixed64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sfixed32")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_sfixed64")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_float")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_double")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_bool")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_string")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_bytes")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeatedgroup")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_nested_message")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_foreign_message")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_import_message")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_nested_enum")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_foreign_enum")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_import_enum")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_string_piece")));
Assert.AreEqual(2, message.GetRepeatedFieldCount(f("repeated_cord")));
Assert.AreEqual(201, message[f("repeated_int32"), 0]);
Assert.AreEqual(202L, message[f("repeated_int64"), 0]);
//.........这里部分代码省略.........