/// <summary> /// Writes the contents of this element to the file when implemented in a derived class. /// </summary> /// <param name="writer">The XmlWriter that writes to the file.</param> /// <param name="serializeCollectionKey">true to serialize only the collection key properties; otherwise, false.</param> /// <returns>true if any data was actually serialized; otherwise, false.</returns> protected internal virtual bool SerializeElement(XmlWriter writer, bool serializeCollectionKey) { PreSerialize(writer); if (serializeCollectionKey) { APXmlPropertyCollection props = GetKeyProperties(); foreach (APXmlProperty prop in props) { writer.WriteAttributeString(prop.Name, prop.ConvertToString(this[prop.Name])); } return(props.Count > 0); } bool wroteData = false; foreach (APXmlPropertyInformation prop in ElementInformation.Properties) { if (prop.IsElement || prop.ValueOrigin == APXmlPropertyValueOrigin.Default) { continue; } if (!object.Equals(prop.Value, prop.DefaultValue)) { writer.WriteAttributeString(prop.Name, prop.GetStringValue()); wroteData = true; } } foreach (APXmlPropertyInformation prop in ElementInformation.Properties) { if (!prop.IsElement) { continue; } APXmlElement val = prop.Value as APXmlElement; if (val != null) { wroteData = val.SerializeToXmlElement(writer, prop.Name) || wroteData; } } return(wroteData); }
/// <summary> /// Overridden. Writes the data to an XML element in the xml file when overridden in a derived class. /// </summary> /// <param name="writer">Output stream that writes XML to the xml file.</param> /// <param name="serializeCollectionKey">true to serialize the collection key; otherwise, false.</param> /// <returns>true if the APXmlElementCollection was written to the xml file successfully.</returns> protected internal override bool SerializeElement(XmlWriter writer, bool serializeCollectionKey) { if (serializeCollectionKey) { return(base.SerializeElement(writer, serializeCollectionKey)); } bool wroteData = false; for (int i = 0; i < _list.Count; i++) { APXmlElement elem = (APXmlElement)_list[i]; elem.SerializeToXmlElement(writer, _addElementName); } wroteData = wroteData || _list.Count > 0; return(wroteData); }