зеркало из https://github.com/App-vNext/corefx.git
Add indexer to ImmutableSortedSet`1+Builder class.
The indexer is available on the immutable type, so its absence from the Builder is notable. Fortunately, it's simple to correct. New tests included.
This commit is contained in:
Родитель
b69964f05a
Коммит
89c99b789d
|
@ -97,6 +97,20 @@ namespace System.Collections.Immutable
|
|||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Gets the element of the set at the given index.
|
||||
/// </summary>
|
||||
/// <param name="index">The 0-based index of the element in the set to return.</param>
|
||||
/// <returns>The element at the given position.</returns>
|
||||
/// <remarks>
|
||||
/// No index setter is offered because the element being replaced may not sort
|
||||
/// to the same position in the sorted collection as the replacing element.
|
||||
/// </remarks>
|
||||
public T this[int index]
|
||||
{
|
||||
get { return this.root[index]; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the maximum value in the collection, as defined by the comparer.
|
||||
/// </summary>
|
||||
|
|
|
@ -313,5 +313,17 @@ namespace System.Collections.Immutable.Test
|
|||
Assert.NotNull(builder.SyncRoot);
|
||||
Assert.Same(builder.SyncRoot, builder.SyncRoot);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Indexer()
|
||||
{
|
||||
var builder = ImmutableSortedSet.Create(1, 3, 2).ToBuilder();
|
||||
Assert.Equal(1, builder[0]);
|
||||
Assert.Equal(2, builder[1]);
|
||||
Assert.Equal(3, builder[2]);
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => builder[-1]);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => builder[3]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче