[Mono-list] GetTypeCode for Enum

Nick Drochak ndrochak@gol.com
Mon, 11 Mar 2002 08:06:27 +0900


In a continuing effort to get the Nunit tests compiled with corlib, I
found that Enum.cs does not yet implement GetTypeCode().  My patch for
it is below.  It's probably overly na´ve, so I'd appreciate feedback.

This method is one of the IConvertible methods needed for Enum, however,
most of the that interface's methods are not public in Enum. So, the way
it's defined the type system probably won't find this method on the
interface like it should. 

I'm not sure how to add the interface to the class without having to
define all the To*() methods as public at the same time.

Maybe all this complication was the reason that method wasn't there in
the first place :)


Thanks,
Nick D.

Index: Enum.cs
===================================================================
RCS file: /cvs/public/mcs/class/corlib/System/Enum.cs,v
retrieving revision 1.14
diff -u -r1.14 Enum.cs
--- Enum.cs	2002/03/01 14:41:46	1.14
+++ Enum.cs	2002/03/10 19:08:50
@@ -27,8 +27,15 @@
 		}
 	};
 
-	[MonoTODO]
+	[MonoTODO("Needs IFormattable, IConvertible and
[Serializable]")]
 	public abstract class Enum : ValueType, IComparable {
+
+		[CLSCompliant(false)]
+		public TypeCode GetTypeCode () {
+			MonoEnumInfo info;
+			MonoEnumInfo.GetInfo (this.GetType (), out
info);
+			return Type.GetTypeCode (info.utype);
+		}
 
 		[MethodImplAttribute(MethodImplOptions.InternalCall)]
 		private extern object get_value ();