Vorrei sapere se "theObject" è un enum (di qualsiasi tipo di enum)
foreach (var item in Enum.GetValues(theObject.GetType())) {
//do something
}
Vorrei sapere se "theObject" è un enum (di qualsiasi tipo di enum)
foreach (var item in Enum.GetValues(theObject.GetType())) {
//do something
}
Risposte:
La domanda è la risposta. :)
bool isEnum = theObject is Enum;
Se hai un Type
, usa la Type.IsEnum
proprietà, ad esempio:
bool isEnum = theObject.GetType().IsEnum;
Type
essere di tipo Enum. +1
Per i parametri di tipo generico, il parametro può essere vincolato anziché testato:
where T : Enum