I gave up and just wrote my own, I'm sure it isn't the best way but hopefully the next person that comes looking for a method that doesn't create random RGB will find this useful. It can be adapted to be more generic by using a T (token) instead.
public static Color GetRandomColor(Random randomiser)
{
//Declare variabels
PropertyInfo[]
propInfo;
Dictionary<string, Color>
colors;
//Get all the properties
propInfo = typeof(Color).GetProperties();
//Setup dictionary
colors = new Dictionary<string, Color>();
//Cycle through each property
for (int propIndex = 0; propIndex < propInfo.Length; propIndex++)
{
//If the current property is type color
if (propInfo[propIndex].PropertyType.IsAssignableFrom(typeof(Color)))
{
//Add current color
colors.Add(propInfo[propIndex].Name, (Color)propInfo[propIndex].GetValue(typeof(Color), null));
}
}
//return the random color
return colors[colors.Keys.ToArray()[randomiser.Next(0, colors.Count)]];
}

New Topic/Question
Reply



MultiQuote




|