Example #1
0
        /// <summary>
        /// Creates a random value of the specified <see cref="Enum"/> type using a uniform distribution
        /// algorithm.
        /// </summary>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="enumType">The <see cref="Enum"/> type.</param>
        /// <returns>A random value of the specified <see cref="Enum"/> type.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> or <paramref name="enumType"/> is <c>null</c>.</exception>
        public static object AnyEnumValue(this IAnonymousData anon, Type enumType)
        {
            Argument.NotNull(anon, nameof(anon));
            Argument.NotNull(enumType, nameof(enumType));
            Argument.IsEnumType(enumType, nameof(enumType));

            return(anon.AnyEnumValue(enumType, Distribution.Uniform));
        }
Example #2
0
        /// <summary>
        /// Creates a random value of the specified <see cref="Enum"/> type using the specified distribution
        /// algorithm.
        /// </summary>
        /// <typeparam name="T">The <see cref="Enum"/> type</typeparam>
        /// <param name="anon">The anonymous data provider to use.</param>
        /// <param name="distribution">The distribution algorithm to use.</param>
        /// <returns>A random value of the specified <see cref="Enum"/> type.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="anon"/> is <c>null</c>.</exception>
        public static T AnyEnumValue <T>(this IAnonymousData anon, Distribution distribution)
        {
            Argument.NotNull(anon, nameof(anon));

            var type = typeof(T);

            if (!type.IsEnum())
            {
                throw new InvalidOperationException("Generic parameter T must be an Enum type.");
            }

            return((T)anon.AnyEnumValue(type, distribution));
        }