EnumerateElementAtIndex() public static method

Returns the element at the specified index using the supplied enumerable.
/// If the supplied was less than zero, or the /// supplied did not contain enough elements /// to be able to reach the supplied . /// /// If the supplied is . ///
public static EnumerateElementAtIndex ( IEnumerable enumerable, int index ) : object
enumerable IEnumerable /// The to use to enumerate /// elements until the supplied is reached. ///
index int /// The index of the element in the enumeration to return. ///
return object
コード例 #1
0
        public void EnumerateElementAtNegativeIndexViaIEnumerable()
        {
            string expected = "Mmm...";
            IList  list     = new string[] { "Aw!", "Man!", expected };

            Assert.Throws <ArgumentOutOfRangeException>(() => ObjectUtils.EnumerateElementAtIndex(list, -10));
        }
コード例 #2
0
        public void EnumerateElementAtNegativeIndexViaIEnumerable()
        {
            string expected = "Mmm...";
            IList  list     = new string[] { "Aw!", "Man!", expected };
            object actual   = ObjectUtils.EnumerateElementAtIndex(list, -10);

            Assert.AreEqual(expected, actual);
        }
コード例 #3
0
        public void EnumerateElementAtOutOfRangeIndex()
        {
            string      expected   = "Mmm...";
            IList       list       = new string[] { "Aw!", "Man!", expected };
            IEnumerator enumerator = list.GetEnumerator();

            Assert.Throws <ArgumentOutOfRangeException>(() => ObjectUtils.EnumerateElementAtIndex(enumerator, 12));
        }
コード例 #4
0
        public void EnumerateElementAtNegativeIndex()
        {
            string      expected   = "Mmm...";
            IList       list       = new string[] { "Aw!", "Man!", expected };
            IEnumerator enumerator = list.GetEnumerator();
            object      actual     = ObjectUtils.EnumerateElementAtIndex(enumerator, -10);

            Assert.AreEqual(expected, actual);
        }
コード例 #5
0
 /// <summary>
 /// Returns the element at the specified index using the supplied
 /// <paramref name="enumerable"/>.
 /// </summary>
 /// <param name="enumerable">
 /// The <see cref="System.Collections.IEnumerable"/> to use to enumerate
 /// elements until the supplied <paramref name="index"/> is reached.
 /// </param>
 /// <param name="index">
 /// The index of the element in the enumeration to return.
 /// </param>
 /// <returns>
 /// The element at the specified index using the supplied
 /// <paramref name="enumerable"/>.
 /// </returns>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// If the supplied <paramref name="index"/> was less than zero, or the
 /// supplied <paramref name="enumerable"/> did not contain enough elements
 /// to be able to reach the supplied <paramref name="index"/>.
 /// </exception>
 /// <exception cref="System.ArgumentNullException">
 /// If the supplied <paramref name="enumerable"/> is <see langword="null"/>.
 /// </exception>
 public static object EnumerateElementAtIndex(IEnumerable enumerable, int index)
 {
     AssertUtils.ArgumentNotNull(enumerable, "enumerable");
     return(ObjectUtils.EnumerateElementAtIndex(enumerable.GetEnumerator(), index));
 }
コード例 #6
0
 /// <summary>
 /// Returns the first element in the supplied <paramref name="enumerator"/>.
 /// </summary>
 /// <param name="enumerator">
 /// The <see cref="System.Collections.IEnumerator"/> to use to enumerate
 /// elements.
 /// </param>
 /// <returns>
 /// The first element in the supplied <paramref name="enumerator"/>.
 /// </returns>
 /// <exception cref="System.IndexOutOfRangeException">
 /// If the supplied <paramref name="enumerator"/> did not have any elements.
 /// </exception>
 public static object EnumerateFirstElement(IEnumerator enumerator)
 {
     return(ObjectUtils.EnumerateElementAtIndex(enumerator, 0));
 }