Groups | Blog | Home
all groups > dotnet clr > november 2007 >

dotnet clr : How to get base data type for enum via reflection


john conwell
11/27/2007 11:03:01 AM
in .Net you can make your Enum inherit from sbyte, byte, short, ushort, int,
uint, long, ulong (default is int).

What I'm trying to do is determine what is the underlying type of a enum at
runtime via reflection. But I cant figure out how. If I get the Type of my
custom emun, it's base type property just says System.Enum, who's base type
is System.Enum (and on and on...).

Is there anyway to figure this out?
Thanks,
john conwell
11/27/2007 11:14:00 AM
Oh, never mind. I found it:

Enum.GetUnderlyingType(typeof(MyCustomEnum))



[quoted text, click to view]
Jon Skeet [C# MVP]
11/27/2007 7:32:45 PM
[quoted text, click to view]

Use Enum.GetUnderlyingType(Type)

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
AddThis Social Bookmark Button