Example #1
0
        /// <summary>
        /// Create the object specified by the assemblyPath and class attributes of node,
        /// and if the resulting object implements IPersistAsXml, call InitXml.
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        static public object RestoreObject(XmlNode node)
        {
            object        obj        = CreateObject(node);
            IPersistAsXml persistObj = obj as IPersistAsXml;

            if (persistObj != null)
            {
                persistObj.InitXml(node);
            }
            return(obj);
        }
Example #2
0
        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);
        }
Example #3
0
        /// <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);
        }