コード例 #1
0
        /// <summary>
        /// Concatenates the array with the specified span of elements.
        /// </summary>
        /// <typeparam name="T">The type of elements in the array.</typeparam>
        /// <param name="left">The array to concatenate.</param>
        /// <param name="right">The tail of concatenation.</param>
        /// <param name="startIndex">The starting index in <paramref name="left"/> at which <paramref name="right"/> should be inserted.</param>
        /// <returns>The array representing all elements from <paramref name="left"/> up to <paramref name="startIndex"/> exclusively including elements from <paramref name="right"/>.</returns>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="startIndex"/> is less than 0 or greater than length of <paramref name="left"/> array.</exception>
        public static T[] Concat <T>(this T[] left, T[] right, long startIndex)
        {
            if (startIndex < 0 || startIndex > Intrinsics.GetLength(left))
            {
                throw new ArgumentOutOfRangeException(nameof(startIndex));
            }
            var result = new T[startIndex + right.LongLength];

            Array.Copy(left, result, startIndex);
            Array.Copy(right, 0L, result, startIndex, right.Length);
            return(result);
        }
コード例 #2
0
ファイル: ObjectExtensions.cs プロジェクト: natilivni/dotNext
        /// <summary>
        /// Checks whether the specified object is equal to one
        /// of the specified objects.
        /// </summary>
        /// <remarks>
        /// This method uses <see cref="object.Equals(object, object)"/>
        /// to check equality between two objects.
        /// </remarks>
        /// <typeparam name="T">The type of object to compare.</typeparam>
        /// <param name="value">The object to compare with other.</param>
        /// <param name="values">Candidate objects.</param>
        /// <returns><see langword="true"/>, if <paramref name="value"/> is equal to one of <paramref name="values"/>.</returns>
        public static bool IsOneOf <T>(this T value, params T?[] values)
            where T : class
        {
            for (nint i = 0; i < Intrinsics.GetLength(values); i++)
            {
                if (Equals(values[i], value))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #3
0
        /// <summary>
        /// Checks whether the specified value is equal to one
        /// of the specified values.
        /// </summary>
        /// <remarks>
        /// This method uses <see cref="IEquatable{T}.Equals(T)"/>
        /// to check equality between two values.
        /// </remarks>
        /// <typeparam name="T">The type of object to compare.</typeparam>
        /// <param name="value">The value to compare with other.</param>
        /// <param name="values">Candidate objects.</param>
        /// <returns><see langword="true"/>, if <paramref name="value"/> is equal to one of <paramref name="values"/>.</returns>
        public static bool IsOneOf <T>(this T value, params T[] values)
            where T : struct, IEquatable <T>
        {
            for (nint i = 0; i < Intrinsics.GetLength(values); i++)
            {
                if (values[i].Equals(value))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #4
0
 /// <summary>
 /// Indicates that array is <see langword="null"/> or empty.
 /// </summary>
 /// <typeparam name="T">Type of elements in the array.</typeparam>
 /// <param name="array">The array to check.</param>
 /// <returns><see langword="true"/>, if array is <see langword="null"/> or empty.</returns>
 public static bool IsNullOrEmpty <T>([NotNullWhen(false)] this T[]?array)
 => array is null || Intrinsics.GetLength(array) == default;