18 using erminas.SmartAPI.CMS.Project;
19 using erminas.SmartAPI.Exceptions;
20 using erminas.SmartAPI.Utils;
22 namespace erminas.SmartAPI.CMS.Converter
24 internal abstract class AbstractGuidElementConverter<T> : IAttributeConverter<T>
27 public virtual T ConvertFrom(
IProjectObject parent, XmlElement element, RedDotAttribute attribute)
32 "{0}.ConvertFrom must be called from a project object", GetType().Name));
36 return element.TryGetGuid(attribute.ElementName, out guid)
37 ? GetFromGuid(parent, element, attribute, guid)
41 public virtual bool IsReadOnly
46 public virtual void WriteTo(
IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,
55 CheckReadOnly(parent.
Project, attribute);
59 element.SetAttributeValue(attribute.ElementName, null);
63 if (ConverterHelper.AreFromTheSameProject(parent, value))
65 element.SetAttributeValue(attribute.ElementName, value.Guid.ToRQLString());
69 T resolvedValue = GetFromName(parent, element, attribute, value);
70 element.SetAttributeValue(attribute.ElementName,
71 resolvedValue != null ? resolvedValue.Guid.ToRQLString() : null);
75 protected void CheckReadOnly(
IProject projectOfTarget, RedDotAttribute attribute)
80 string.Format(
"Writing to attribute {0} is forbidden", attribute.Description));
84 protected abstract T GetFromGuid(
IProjectObject parent, XmlElement element, RedDotAttribute attribute, Guid guid);
86 protected abstract T GetFromName(
IProjectObject parent, IXmlReadWriteWrapper element, RedDotAttribute attribute,