/// <summary> /// Writes the configuration data to an XML element in the configuration file when overridden in a derived class. /// </summary> /// <param name="writer">Output stream that writes XML to the configuration file.</param> /// <param name="serializeCollectionKey">true to serialize the collection key; otherwise, false.</param> /// <returns>true if the collection was written to the configuration 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++) { APGenElement elem = (APGenElement)_list[i]; elem.SerializeToXmlElement(writer, _addElementName); } wroteData = wroteData || _list.Count > 0; return(wroteData); }
/// <summary> /// Writes the contents of this configuration element to the configuration file when implemented in a derived class. /// </summary> /// <param name="writer">The XmlWriter that writes to the configuration 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) { APGenPropertyCollection props = GetKeyProperties(); foreach (APGenProperty prop in props) writer.WriteAttributeString(prop.Name, prop.ConvertToString(this[prop.Name])); return props.Count > 0; } bool wroteData = false; foreach (APGenPropertyInformation prop in ElementInformation.Properties) { if (prop.IsElement || prop.ValueOrigin == APGenPropertyValueOrigin.Default) continue; if (!object.Equals(prop.Value, prop.DefaultValue)) { writer.WriteAttributeString(prop.Name, prop.GetStringValue()); wroteData = true; } } foreach (APGenPropertyInformation prop in ElementInformation.Properties) { if (!prop.IsElement) continue; APGenElement val = prop.Value as APGenElement; if (val != null) wroteData = val.SerializeToXmlElement(writer, prop.Name) || wroteData; } return wroteData; }