GetEnumValues() public static method

Gets the values for an enumeration, using Enum.GetTypes where available, otherwise through reflection.
public static GetEnumValues ( Type enumType ) : Array
enumType System.Type
return System.Array
示例#1
0
        /// <summary>
        /// Return an array of random Enums
        /// </summary>
        /// <param name="count"></param>
        /// <param name="enumType"></param>
        /// <returns></returns>
        public object[] GetEnums(int count, Type enumType)
        {
            if (!enumType.IsEnum)
            {
                throw new ArgumentException(string.Format("The specified type: {0} was not an enum", enumType));
            }

            Array values = TypeHelper.GetEnumValues(enumType);

            object[] rvals = new Enum[count];

            for (int index = 0; index < count; index++)
            {
                rvals[index] = values.GetValue(Next(values.Length));
            }

            return(rvals);
        }
示例#2
0
        /// <summary>
        /// Return a random enum value representation of the specified Type
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns> T </returns>
        public T GetEnum <T>()
        {
            Array enums = TypeHelper.GetEnumValues(typeof(T));

            return((T)enums.GetValue(Rand.Next(0, enums.Length)));
        }
示例#3
0
        /// <summary>
        /// Return a random enum value from the specified type
        /// </summary>
        /// <param name="enumType"></param>
        /// <returns> object </returns>
        public object GetEnum(Type enumType)
        {
            Array enums = TypeHelper.GetEnumValues(enumType);

            return(enums.GetValue(Rand.Next(0, enums.Length)));
        }
示例#4
0
        /// <summary>
        /// Returns a random enum value of the specified Type as an object.
        /// </summary>
        public object NextEnum(Type type)
        {
            Array enums = TypeHelper.GetEnumValues(type);

            return(enums.GetValue(Next(0, enums.Length)));
        }