HighTechTalks DotNet Forums  

How to get base data type for enum via reflection

Dotnet Framework (CLR) microsoft.public.dotnet.framework.clr


Discuss How to get base data type for enum via reflection in the Dotnet Framework (CLR) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
john conwell
 
Posts: n/a

Default How to get base data type for enum via reflection - 11-27-2007 , 02:03 PM






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,


Reply With Quote
  #2  
Old   
john conwell
 
Posts: n/a

Default RE: How to get base data type for enum via reflection - 11-27-2007 , 02:14 PM






Oh, never mind. I found it:

Enum.GetUnderlyingType(typeof(MyCustomEnum))



"john conwell" wrote:

Quote:
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,


Reply With Quote
  #3  
Old   
Jon Skeet [C# MVP]
 
Posts: n/a

Default Re: How to get base data type for enum via reflection - 11-27-2007 , 02:32 PM



john conwell <johnconwell (AT) discussions (DOT) microsoft.com> wrote:
Quote:
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?
Use Enum.GetUnderlyingType(Type)

--
Jon Skeet - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.