Reputation: 23935
I would like to know if 'theObject' is an enum (of any enum type)
foreach (var item in Enum.GetValues(theObject.GetType())) {
//do something
}
Upvotes: 105
Views: 48509
Reputation: 3142
For generic type parameters, the parameter can be constrained rather than tested:
where T : Enum
Upvotes: 6
Reputation: 29466
If you have a Type
, use the Type.IsEnum
property, e.g.:
bool isEnum = theObject.GetType().IsEnum;
Upvotes: 76