|
|
@@ -83,12 +83,21 @@ namespace System.ComponentModel
|
|
|
|
|
|
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)) {
|