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;
}