private void WriteElement( XmlWriter writer, XmlNamespaceManager manager, Element element, TypeBrowser.ElementInfo elementInfo) { object value = elementInfo.GetValue(element); // Make sure it needs saving if (value != null) { if (value is IEnumerable <Element> collection) { foreach (Element child in collection) { this.SerializeElement(writer, manager, child); } } else if (string.IsNullOrEmpty(elementInfo.Component.Name)) { // If the component is null then it's a normal element this.SerializeElement(writer, manager, (Element)value); } else { writer.WriteStartElement(elementInfo.Component.Name, elementInfo.Component.Namespace); WriteData(writer, this.GetString(value)); writer.WriteEndElement(); } } }
private static IEnumerable <Element> GetPropertyElements(Element element, TypeBrowser.ElementInfo info) { // All properties with their ElementName set to null will be Elements // Check here to avoid the GetValue the property is not an Element. if (string.IsNullOrEmpty(info.Component.Name)) { object value = info.GetValue(element); if (value is IEnumerable <Element> collection) { foreach (Element e in collection) { yield return(e); } } else if (value is Element propertyElement) { yield return(propertyElement); } } }