Adding XmlHelper support for enums

This commit is contained in:
Sebastien Ros
2013-10-30 09:56:09 -07:00
parent 57b98724a9
commit 0c35d28f17

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Linq.Expressions;
using System.Xml;
using System.Xml.Linq;
using NHibernate.Util;
using Orchard.Utility;
namespace Orchard.ContentManagement {
@@ -212,6 +213,10 @@ namespace Orchard.ContentManagement {
return decimalValue.ToString(CultureInfo.InvariantCulture);
}
if (type.IsEnum) {
return value.ToString();
}
throw new NotSupportedException(String.Format("Could not handle type {0}", type.Name));
}
@@ -262,6 +267,11 @@ namespace Orchard.ContentManagement {
if (type == typeof(decimal) || type == typeof(decimal?)) {
return (T)(object)decimal.Parse(value, CultureInfo.InvariantCulture);
}
if (type.IsEnum) {
return (T)Enum.Parse(type, value);
}
throw new NotSupportedException(String.Format("Could not handle type {0}", type.Name));
}