vorrei sapere se 'theObject' è un enum (di qualsiasi tipo enum)prova se un oggetto è un Enum
foreach (var item in Enum.GetValues(theObject.GetType())) {
//do something
}
vorrei sapere se 'theObject' è un enum (di qualsiasi tipo enum)prova se un oggetto è un Enum
foreach (var item in Enum.GetValues(theObject.GetType())) {
//do something
}
La domanda è la risposta. :)
bool isEnum = theObject is Enum;
Se si dispone di un Type
, utilizzare la proprietà Type.IsEnum
, ad esempio:
bool isEnum = theObject.GetType().IsEnum;
Questo ha funzionato per me. Non riuscivo a capire come far funzionare la risposta accettata in VB.NET. –
In realtà avevo bisogno di sapere come verificare che 'Type' fosse un tipo Enum. +1 – Nathan
basta usare
if (theObject is Enum)
//is an enum
Lo adoro! E ancora più vicino alla domanda: if (theObject is Enum) {...} –
With Poetry! Bello. – Custodio
Questo non è nemmeno quello per cui sono venuto qui e ti sto dando un punto. È così ... pulito ..., è un bellissimo uomo T.T –
Lukas