C# Test if an object is an Enum
- by Aran Mulholland
I would like to know if 'theObject' is an enum (of any enum type)
foreach (var item in Enum.GetValues(theObject.GetType())) {
//make sure we have all the enumeration values in the collection
if (this.ValuesCollection.Contains(item)) { }
else {
this.ValuesCollection.Add(item);
}
Console.WriteLine(item.ToString());
Console.WriteLine(item.GetType().ToString());
}