17 using System.Globalization;
19 using erminas.SmartAPI.CMS.Project;
20 using erminas.SmartAPI.Exceptions;
21 using erminas.SmartAPI.Utils;
23 namespace erminas.SmartAPI.CMS.Converter
25 internal class EnumConverter<T> : IAttributeConverter<T> where T : struct, IConvertible
27 public T ConvertFrom(
IProjectObject parent, XmlElement element, RedDotAttribute attribute)
34 var strValue = element.GetAttributeValue(attribute.ElementName);
35 if (
string.IsNullOrEmpty(strValue) || strValue ==
"#" + parent.
Session.
SessionKey)
40 const bool IGNORE_CASE =
true;
41 return (T) Enum.Parse(typeof (T), strValue, IGNORE_CASE);
44 public bool IsReadOnly
49 public void WriteTo(
IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute, T value)
51 element.SetAttributeValue(attribute.ElementName,
52 value.ToInt32(CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture));