Exemplo n.º 1
0
        /// <summary>
        /// Adds the specified content as children of this System.Xml.Linq.XContainer.
        /// </summary>
        /// <param name="content">
        /// A content object containing simple content or a collection of content objects
        /// to be added.
        /// </param>
        public void Add(object content)
        {
            if (content is XNode)
            {
                XNode contentAsXNode = ((XNode)content);
                if (contentAsXNode.HasParent())
                {
                    contentAsXNode = contentAsXNode.Clone();
                }
                CSHTML5.Interop.ExecuteJavaScriptAsync(@"$0.appendChild($1)", INTERNAL_jsnode, contentAsXNode.INTERNAL_jsnode);
            }
            else if (content is XAttribute)
            {
                XAttribute contentAsXAttribute = (XAttribute)content;
                if (contentAsXAttribute.INTERNAL_containerJSNode == null)
                {
                    contentAsXAttribute.INTERNAL_containerJSNode = INTERNAL_jsnode;
                }
                else
                {
                    XAttribute attributeCopy = new XAttribute(contentAsXAttribute);
                    attributeCopy.INTERNAL_containerJSNode = INTERNAL_jsnode;
                }


                if (string.IsNullOrWhiteSpace(contentAsXAttribute.Name.NamespaceName))
                {
                    CSHTML5.Interop.ExecuteJavaScriptAsync("$0.setAttribute($1, $2)", INTERNAL_jsnode, contentAsXAttribute._nameWithPrefix.LocalName, contentAsXAttribute.Value);
                }
                else
                {
                    XName  attributeName      = contentAsXAttribute._nameWithPrefix;
                    string attributeLocalName = attributeName.LocalName;
                    if (attributeName.NamespaceName == DataContractSerializer_Helpers.XMLNS_NAMESPACE && !attributeName.LocalName.StartsWith("xmlns:"))
                    {
                        attributeLocalName = "xmlns:" + attributeLocalName; //this is required to have DataContractSerializer_Helpers.XMLNS_NAMESPACE as the namespace.
                    }
                    CSHTML5.Interop.ExecuteJavaScriptAsync("$0.setAttributeNS($1, $2, $3)", INTERNAL_jsnode, attributeName.NamespaceName, attributeLocalName, contentAsXAttribute.Value);
                }
            }
        }