Added handling of nullable enums.

This enables content parts to use infoset storage with nullable enum types.
Before this change, the NotSupportedException would be thrown.
This commit is contained in:
Sipke Schoorstra
2015-12-30 14:20:26 +01:00
parent bd1a1eb6e6
commit 64d8c1a16f

View File

@@ -214,7 +214,9 @@ namespace Orchard.ContentManagement {
return decimalValue.ToString(CultureInfo.InvariantCulture); return decimalValue.ToString(CultureInfo.InvariantCulture);
} }
if (type.IsEnum) { var underlyingType = Nullable.GetUnderlyingType(type) ?? type;
if (underlyingType.IsEnum) {
return value.ToString(); return value.ToString();
} }
@@ -275,8 +277,10 @@ namespace Orchard.ContentManagement {
return (T)(object)decimal.Parse(value, CultureInfo.InvariantCulture); return (T)(object)decimal.Parse(value, CultureInfo.InvariantCulture);
} }
if (type.IsEnum) { var underlyingType = Nullable.GetUnderlyingType(type) ?? type;
return (T)Enum.Parse(type, value);
if (underlyingType.IsEnum) {
return (T)Enum.Parse(underlyingType, value);
} }
throw new NotSupportedException(String.Format("Could not handle type {0}", type.Name)); throw new NotSupportedException(String.Format("Could not handle type {0}", type.Name));