示例#1
0
        /// <summary>
        /// Converts the collection to a read-only array.
        /// </summary>
        /// <typeparam name="T">The type of array elements.</typeparam>
        /// <param name="collection">the collection of elements</param>
        /// <returns>an read only array instance containing the elements in the collection.</returns>
        public static ReadOnlyArray <T> ToReadOnlyArray <T>(this IEnumerable <T> collection)
        {
            Contract.Requires(collection != null);
            Contract.Ensures(Contract.Result <ReadOnlyArray <T> >().IsValid);

            return(ReadOnlyArray <T> .From(collection));
        }
示例#2
0
        /// <summary>
        /// Creates an instance of this structure.
        /// </summary>
        public static ItemResources Create(int[] semaphoreIncrements)
        {
            // chop off trailing zeros to normalize
            if (semaphoreIncrements != null)
            {
                for (int i = semaphoreIncrements.Length - 1; i >= 0; i--)
                {
                    if (semaphoreIncrements[i] != 0)
                    {
                        return(new ItemResources(ReadOnlyArray <int> .From(semaphoreIncrements, 0, i + 1)));
                    }
                }
            }

            return(Empty);
        }
示例#3
0
        /// <summary>
        /// Converts the collection to a read-only array.
        /// </summary>
        /// <typeparam name="T">The type of array elements.</typeparam>
        /// <param name="collection">the collection of elements</param>
        /// <returns>an read only array instance containing the elements in the collection.</returns>
        public static ReadOnlyArray<T> ToReadOnlyArray<T>(this IEnumerable<T> collection)
        {
            Contract.RequiresNotNull(collection);

            return ReadOnlyArray<T>.From(collection);
        }