Hey Jan,

On Wed, Apr 14, 2010 at 5:15 PM, Jan <[email protected]> wrote:
> I have an enum TypeDefinition and I need the primitive type behind
> that.

                public static TypeReference GetEnumUnderlyingType (this 
TypeDefinition self)
                {
                        if (self == null)
                                throw new ArgumentNullException ("self");
                        if (!self.IsEnum)
                                throw new ArgumentException ();

                        var fields = self.Fields;

                        for (int i = 0; i < fields.Count; i++) {
                                var field = fields [i];
                                if (!field.IsStatic)
                                        return field.FieldType;
                        }

                        throw new ArgumentException ();
                }

I'll add that to Mono.Cecil.Rocks tonight.

-- 
Jb Evain  <[email protected]>

-- 
--
mono-cecil

Reply via email to