/// <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); }
/// <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))); }
/// <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))); }
/// <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))); }