Author: ivanz
Date: 2007-08-30 15:40:43 -0400 (Thu, 30 Aug 2007)
New Revision: 85069
Modified:
trunk/mcs/class/System/System.ComponentModel/ChangeLog
trunk/mcs/class/System/System.ComponentModel/EnumConverter.cs
Log:
2007-08-30 Ivan N. Zlatev <[EMAIL PROTECTED]>
* EnumConverter.cs: Implemented conversion to InstanceDescriptor
for enums with a FlagsAttribute. Fixes #82118.
Modified: trunk/mcs/class/System/System.ComponentModel/ChangeLog
===================================================================
--- trunk/mcs/class/System/System.ComponentModel/ChangeLog 2007-08-30
19:20:31 UTC (rev 85068)
+++ trunk/mcs/class/System/System.ComponentModel/ChangeLog 2007-08-30
19:40:43 UTC (rev 85069)
@@ -1,3 +1,8 @@
+2007-08-30 Ivan N. Zlatev <[EMAIL PROTECTED]>
+
+ * EnumConverter.cs: Implemented conversion to InstanceDescriptor
+ for enums with a FlagsAttribute. Fixes #82118.
+
2007-08-29 Ivan N. Zlatev <[EMAIL PROTECTED]>
* DesignerOptionService.cs: implemented.
Modified: trunk/mcs/class/System/System.ComponentModel/EnumConverter.cs
===================================================================
--- trunk/mcs/class/System/System.ComponentModel/EnumConverter.cs
2007-08-30 19:20:31 UTC (rev 85068)
+++ trunk/mcs/class/System/System.ComponentModel/EnumConverter.cs
2007-08-30 19:40:43 UTC (rev 85069)
@@ -83,12 +83,21 @@
return Enum.Format (type, value, "G");
} else if (destinationType == typeof
(InstanceDescriptor) && value != null) {
- string fieldName = ConvertToString (context,
- culture, value);
- FieldInfo f = type.GetField (fieldName);
- if (f == null)
- throw CreateValueNotValidException
(value);
- return new InstanceDescriptor (f, null);
+ string enumString = ConvertToString (context,
culture, value);
+ if (type.IsDefined (typeof (FlagsAttribute),
false) && enumString.IndexOf (",") != -1) {
+ if (value is IConvertible) {
+ Type underlyingType =
Enum.GetUnderlyingType (type);
+ object enumValue =
((IConvertible)value).ToType (underlyingType, culture);
+ MethodInfo toObjectMethod =
typeof (Enum).GetMethod ("ToObject", new Type[] { typeof (Type),
+
underlyingType });
+ return new InstanceDescriptor
(toObjectMethod, new object[] { type, enumValue });
+ }
+ } else {
+ FieldInfo f = type.GetField
(enumString);
+ if (f == null)
+ throw
CreateValueNotValidException (value);
+ return new InstanceDescriptor (f, null);
+ }
#if NET_2_0
} else if (destinationType == typeof (Enum[]) && value
!= null) {
if (!type.IsDefined (typeof (FlagsAttribute),
false)) {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches