protected void WriteNamespaceDeclarations(XmlSerializerNamespaces xmlns)
{
if (xmlns != null)
{
foreach (KeyValuePair<string, string> entry in xmlns.Namespaces)
{
string prefix = (string)entry.Key;
string ns = (string)entry.Value;
if (_namespaces != null)
{
string oldNs = _namespaces.Namespaces[prefix] as string;
if (oldNs != null && oldNs != ns)
{
throw new InvalidOperationException(SR.Format(SR.XmlDuplicateNs, prefix, ns));
}
}
string oldPrefix = (ns == null || ns.Length == 0) ? null : Writer.LookupPrefix(ns);
if (oldPrefix == null || oldPrefix != prefix)
{
WriteAttribute(nameof(xmlns), prefix, null, ns);
}
}
}
_namespaces = null;
}