Implement RepeatedField.AddRange.

This fixes issue #1730.
pull/1785/head
Jon Skeet 9 years ago
parent d9334ea8d9
commit b053b9211b
  1. 10
      csharp/src/Google.Protobuf.Test/Collections/RepeatedFieldTest.cs
  2. 14
      csharp/src/Google.Protobuf/Collections/RepeatedField.cs

@ -74,6 +74,16 @@ namespace Google.Protobuf.Collections
Assert.AreEqual("bar", list[1]);
}
[Test]
public void AddRange()
{
var list = new RepeatedField<string>();
list.AddRange(new[] { "foo", "bar" });
Assert.AreEqual(2, list.Count);
Assert.AreEqual("foo", list[0]);
Assert.AreEqual("bar", list[1]);
}
[Test]
public void Add_RepeatedField()
{

@ -307,7 +307,7 @@ namespace Google.Protobuf.Collections
/// Adds all of the specified values into this collection.
/// </summary>
/// <param name="values">The values to add to this collection.</param>
public void Add(IEnumerable<T> values)
public void AddRange(IEnumerable<T> values)
{
ProtoPreconditions.CheckNotNull(values, nameof(values));
// TODO: Check for ICollection and get the Count, to optimize?
@ -317,6 +317,18 @@ namespace Google.Protobuf.Collections
}
}
/// <summary>
/// Adds all of the specified values into this collection. This method is present to
/// allow repeated fields to be constructed from queries within collection initializers.
/// Within non-collection-initializer code, consider using the equivalent <see cref="AddRange"/>
/// method instead for clarity.
/// </summary>
/// <param name="values">The values to add to this collection.</param>
public void Add(IEnumerable<T> values)
{
AddRange(values);
}
/// <summary>
/// Returns an enumerator that iterates through the collection.
/// </summary>

Loading…
Cancel
Save