Description

Helper methods for ReturnGraph

Static Methods

Method Description
AllEnumNames Returns an array of strings containing the unique names of an Enum's values.
AllEnumValues<T> Returns an array containing each unique value of an Enum
Random<T> Returns a random item from a list
	
public static string[] AllEnumNames(Type enumType)
{
    if (!enumType.IsEnum)
    {
        throw new ArgumentException(enumType.FullName + " is not an enum");
    }
    
    return Enum.GetNames(enumType);
}

public static T[] AllEnumValues<T>() where T : Enum
{
    return Enum.GetValues(typeof(T)).Cast<T>().ToArray();
}

public static T Random<T>(this IList<T> items) 
{
    if (items == null) throw new ArgumentException("Cannot randomly pick an item from the list, the list is null!");
    if (items.Count == 0) throw new ArgumentException("Cannot randomly pick an item from the list, there are no items in the list!");

    return items[new Random().Next(0, items.Count)];
}