public string[] Update(XmlDocument document, ISerializerHost host = null)
        {
            if (document == null)
            {
                throw new ArgumentNullException("document");
            }
            Dictionary <string, ExtensionNamespaceCounter> dictionary = (host == null) ? new Dictionary <string, ExtensionNamespaceCounter>() : host.GetExtensionNamespaces().ToDictionary((ExtensionNamespace v) => v.Namespace, (ExtensionNamespace v) => new ExtensionNamespaceCounter(v));
            XmlElement documentElement = document.DocumentElement;

            if (documentElement == null)
            {
                throw new InvalidOperationException("Document contains no elements");
            }
            this.AddMustUnderstandNamespaces(dictionary, documentElement);
            this.AddXmlnsNamespaces(dictionary, documentElement);
            this.UpdateLocalNames(documentElement, dictionary);
            ExtensionNamespace[] array = (from v in dictionary
                                          where v.Value.Count > 0
                                          select v.Value.ExtensionNamespace).ToArray();
            NamespaceUpdater.UpdateRootNamespaces(array, documentElement);
            string[] array2 = (from v in array
                               where v.MustUnderstand
                               select v.LocalName).ToArray();
            string text = string.Join(" ", array2);

            if (text.Any())
            {
                documentElement.SetAttribute("MustUnderstand", text);
            }
            else
            {
                documentElement.RemoveAttribute("MustUnderstand");
            }
            return(array2);
        }
        public string[] Update(XmlWriter writer, string xml, ISerializerHost host = null)
        {
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(xml);
            NamespaceUpdater namespaceUpdater = new NamespaceUpdater();

            string[] result = namespaceUpdater.Update(xmlDocument, host);
            xmlDocument.Save(writer);
            return(result);
        }
        public void Serialize(XmlWriter writer, object root)
        {
            XmlDocument    xmlDocument    = new XmlDocument();
            XPathNavigator xPathNavigator = xmlDocument.CreateNavigator();

            using (XmlWriter xmlWriter = xPathNavigator.AppendChild())
            {
                xmlWriter.WriteStartDocument();
                this.WriteObject(xmlWriter, root, null, null, null, 0);
                xmlWriter.WriteEndDocument();
            }
            NamespaceUpdater namespaceUpdater = new NamespaceUpdater();

            namespaceUpdater.Update(xmlDocument, base.Host);
            xmlDocument.Save(writer);
        }