System.Xml.Xsl.Runtime.XmlQueryOutput.CheckAttributePrefix C# (CSharp) Method

CheckAttributePrefix() private method

If attribute's prefix conflicts with other prefixes then redeclare the prefix. If the prefix has not yet been declared, then add it to the namespace manager.
private CheckAttributePrefix ( string prefix, string ns ) : string
prefix string
ns string
return string
        private string CheckAttributePrefix(string prefix, string ns) {
            string nsExisting;
            Debug.Assert(prefix.Length != 0 && ns.Length != 0);

            // Ensure that this attribute's prefix does not conflict with previously declared prefixes in this scope
            if (this.nsmgr == null) {
                // If namespace manager has no namespaces, then there is no possibility of conflict
                WriteNamespaceDeclarationUnchecked(prefix, ns);
            }
            else {
                while (true) {
                    // If prefix is already mapped to a different namespace,
                    nsExisting = this.nsmgr.LookupNamespace(prefix);
                    if (nsExisting != ns) {

                        // Then if the prefix is already mapped,
                        if (nsExisting != null) {
                            // Then there is a conflict that must be resolved by finding another prefix
                            // Always find a new prefix, even if the conflict didn't occur in the current scope
                            // This decision allows more aggressive namespace analysis at compile-time
                            prefix = RemapPrefix(prefix, ns, false);
                            continue;
                        }

                        // Add the mapping to the current scope
                        AddNamespace(prefix, ns);
                    }
                    break;
                }
            }

            return prefix;
        }