From 64d8c1a16f6bdc7e2afff0417b9f7ab4cdd9264a Mon Sep 17 00:00:00 2001 From: Sipke Schoorstra Date: Wed, 30 Dec 2015 14:20:26 +0100 Subject: [PATCH] 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. --- src/Orchard/ContentManagement/XmlHelper.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Orchard/ContentManagement/XmlHelper.cs b/src/Orchard/ContentManagement/XmlHelper.cs index 2e9bfce70..5c015c199 100644 --- a/src/Orchard/ContentManagement/XmlHelper.cs +++ b/src/Orchard/ContentManagement/XmlHelper.cs @@ -214,7 +214,9 @@ namespace Orchard.ContentManagement { return decimalValue.ToString(CultureInfo.InvariantCulture); } - if (type.IsEnum) { + var underlyingType = Nullable.GetUnderlyingType(type) ?? type; + + if (underlyingType.IsEnum) { return value.ToString(); } @@ -275,8 +277,10 @@ namespace Orchard.ContentManagement { return (T)(object)decimal.Parse(value, CultureInfo.InvariantCulture); } - if (type.IsEnum) { - return (T)Enum.Parse(type, value); + var underlyingType = Nullable.GetUnderlyingType(type) ?? type; + + if (underlyingType.IsEnum) { + return (T)Enum.Parse(underlyingType, value); } throw new NotSupportedException(String.Format("Could not handle type {0}", type.Name));