16 using System.Globalization;
18 using erminas.SmartAPI.CMS.Project;
19 using erminas.SmartAPI.CMS.Project.ContentClasses.Elements;
20 using erminas.SmartAPI.Utils;
22 namespace erminas.SmartAPI.CMS.Converter
24 internal class DateTimeFormatConverter : IAttributeConverter<IDateTimeFormat>
26 public IDateTimeFormat ConvertFrom(
IProjectObject parent, XmlElement element, RedDotAttribute attribute)
28 string value = element.GetAttributeValue(attribute.ElementName);
30 int? type = element.IsAttributeSet(parent, attribute.ElementName) && !value.Contains(
"EmptyBuffer")
31 ? element.GetIntAttributeValue(attribute.ElementName)
35 bool valid =
int.TryParse(element.GetAttributeValue(
"eltlcid"), out lcid);
36 if (!valid || type == null || IsCustomFormat(type))
42 ((
IContentClassElement) parent).ContentClass.Project.Session.Locales[lcid].DateTimeFormats[type.Value];
45 public bool IsReadOnly
50 public void WriteTo(
IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,
51 IDateTimeFormat value)
53 element.SetAttributeValue(attribute.ElementName, value.TypeId.ToString(CultureInfo.InvariantCulture));
56 private static bool IsCustomFormat(
int? type)