* Type.cs: Implement new v4 GetEnumUnderlyingType ().
svn path=/trunk/mcs/; revision=152241
+2010-02-22 Rodrigo Kumpera <rkumpera@novell.com>
+
+ * Type.cs: Implement new v4 GetEnumUnderlyingType ().
+
2010-02-22 Rodrigo Kumpera <rkumpera@novell.com>
* Type.cs: Implement new v4 GetTypeCodeImpl ().
{
return !Object.ReferenceEquals (left, right);
}
+
+
+ public virtual Type GetEnumUnderlyingType () {
+ if (!IsEnum)
+ throw new ArgumentException ("Type is not an enumeration", "enumType");
+
+ var fields = GetFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
+
+ if (fields == null || fields.Length != 1)
+ throw new ArgumentException ("An enum must have exactly one instance field", "enumType");
+
+ return fields [0].FieldType;
+ }
#endif
[MethodImplAttribute(MethodImplOptions.InternalCall)]