Ejemplo n.º 1
0
        /// <summary>
        ///   Retrieves the item at the index specified.
        /// </summary>
        /// <typeparam name="TTuple">The tuple type.</typeparam>
        /// <typeparam name="TItem">The item type.</typeparam>
        /// <param name="tuple">The tuple.</param>
        /// <param name="index">The index of the item to retrieve.</param>
        /// <returns>The item located at the <paramref name="index"/> specified.</returns>
        /// <exception cref="InvalidCastException">
        ///   The item located at <paramref name="index"/> cannot be cast to type <typeparamref name="TItem"/>.
        /// </exception>
        public static TItem GetTupleItem <TTuple, TItem>([NotNull] this TTuple tuple, int index)
            where TTuple : class, IStructuralEquatable, IStructuralComparable, IComparable
        {
            Type t = GetIndexType(tuple, index);

            if (!typeof(TItem).IsAssignableFrom(t))
            {
                throw new InvalidCastException(
                          string.Format(
                              // ReSharper disable once AssignNullToNotNullAttribute
                              Resources.ExtendedTuple_CannotCastItemAtIndex,
                              index,
                              t,
                              typeof(TItem)));
            }
            return((TItem)ExtendedTuple <TTuple> .Indexer(tuple, index));
        }
Ejemplo n.º 2
0
 /// <summary>
 ///   Gets the indexer for the specified <see cref="Tuple"/>.
 /// </summary>
 /// <typeparam name="T">The tuple type.</typeparam>
 /// <param name="tuple">The tuple whose indexer we want.</param>
 /// <returns>
 ///   A function that takes an index and retrieves the corresponding item from the specified <paramref name="tuple"/>.
 /// </returns>
 public static Func <int, object> GetTupleIndexer <T>([NotNull] this T tuple)
     where T : class, IStructuralEquatable, IStructuralComparable, IComparable
 {
     return(i => ExtendedTuple <T> .Indexer(tuple, i));
 }