static public XmlNode PersistObject(object src, XmlNode parent, string elementName) { IPersistAsXml obj = src as IPersistAsXml; XmlNode node = parent.OwnerDocument.CreateElement(elementName); parent.AppendChild(node); AddAssemblyClassInfoTo(node, obj); if (obj != null) { obj.PersistAsXml(node); } return(node); }
/// <summary> /// Creates a string representation of the supplied object, an XML string /// containing the required assemblyPath and class attributes needed to create an /// instance using CreateObject, plus whatever gets added to the node by passsing /// it to the PersistAsXml method of the object. The root element name is supplied /// as the elementName argument. /// </summary> /// <param name="obj"></param> /// <param name="elementName"></param> /// <returns></returns> static public string PersistObject(object src, string elementName) { if (src == null) { return(null); } IPersistAsXml obj = src as IPersistAsXml; XmlDocument doc = new XmlDocument(); doc.LoadXml("<" + elementName + "/>"); XmlNode root = doc.DocumentElement; AddAssemblyClassInfoTo(root, src); if (obj != null) { obj.PersistAsXml(root); } return(root.OuterXml); }