ソースを参照

2008-04-16 Zoltan Varga <[email protected]>

	* Binder.cs: Applied patch from Yves Bastide ([email protected]). Add 
	support for converting integers to enums. Fixes #380361.

svn path=/trunk/mcs/; revision=100862
Zoltan Varga 17 年 前
コミット
8f7ceaacdb

+ 11 - 3
mcs/class/corlib/System.Reflection/Binder.cs

@@ -214,6 +214,8 @@ namespace System.Reflection
 
 				if (check_type (vtype, type)) {
 					// These are not supported by Convert
+					if (type.IsEnum)
+						return Enum.ToObject (type, value);
 					if (vtype == typeof (Char)) {
 						if (type == typeof (double))
 							return (double)(char)value;
@@ -239,15 +241,21 @@ namespace System.Reflection
 				if (from == null)
 					return true;
 
-				TypeCode fromt = Type.GetTypeCode (from);
-				TypeCode tot = Type.GetTypeCode (to);
-
 				if (to.IsByRef != from.IsByRef)
 					return false;
 
 				if (to.IsInterface)
 					return to.IsAssignableFrom (from);
 
+				if (to.IsEnum) {
+					to = Enum.GetUnderlyingType (to);
+					if (from == to)
+						return true;
+				}
+
+				TypeCode fromt = Type.GetTypeCode (from);
+				TypeCode tot = Type.GetTypeCode (to);
+
 				switch (fromt) {
 				case TypeCode.Char:
 					switch (tot) {

+ 5 - 0
mcs/class/corlib/System.Reflection/ChangeLog

@@ -1,3 +1,8 @@
+2008-04-16  Zoltan Varga  <[email protected]>
+
+	* Binder.cs: Applied patch from Yves Bastide ([email protected]). Add 
+	support for converting integers to enums. Fixes #380361.
+
 2008-04-02  Andreas Nahr  <[email protected]>
 
 	* IReflect.cs