public void MarkToRenderForVisiblyUsedPrefix(string prefix, bool searchOuterContext, IAncestralNamespaceContextProvider context)
 {
     if (!MarkToRender(prefix, searchOuterContext, context, false))
     {
         string nodeName = context != null ? context.CurrentNodeName : null;
         throw new XmlException(string.Format("Unable to find prefix: {0}, {1}", prefix, nodeName));
     }
 }
        private bool MarkToRender(string prefix, bool searchOuterContext, IAncestralNamespaceContextProvider context, bool isInclusivePrefix)
        {
            if (prefix == "xml")
            {
                return(true);
            }
            bool currentFrame = true;

            for (int i = _namespaceContext.Count - 1; i >= 0; i--)
            {
                NamespaceEntry ne = _namespaceContext[i];
                if (ne == null)
                {
                    if (isInclusivePrefix)
                    {
                        break;
                    }
                    currentFrame = false;
                }
                else if (ne.Prefix == prefix)
                {
                    if (ne.Rendered)
                    {
                        return(true);
                    }
                    bool shouldRender;
                    if (prefix.Length > 0 || ne.NamespaceUri.Length > 0)
                    {
                        shouldRender = true;
                    }
                    else
                    {
                        NamespaceEntry match = null;
                        for (int j = i - 1; j >= 0; j--)
                        {
                            NamespaceEntry p = _namespaceContext[j];
                            if (p != null && p.Rendered && p.Prefix.Length == 0)
                            {
                                match = p;
                                break;
                            }
                        }
                        shouldRender = match != null && match.NamespaceUri.Length > 0;
                    }
                    if (shouldRender)
                    {
                        if (currentFrame)
                        {
                            ne.Rendered = true;
                        }
                        else
                        {
                            _namespaceContext.Add(CloneNamespaceEntryToRender(ne));
                        }
                    }
                    return(true);
                }
            }

            if (searchOuterContext)
            {
                string namespaceUri;
                if (context != null)
                {
                    namespaceUri = context.LookupNamespace(prefix);
                }
                else
                {
                    namespaceUri = null;
                }
                if (namespaceUri != null && namespaceUri.Length > 0)
                {
                    _namespaceContext.Add(CreateNamespaceEntry(prefix, namespaceUri, true));
                    return(true);
                }
                else
                {
                    return(prefix.Length == 0 || isInclusivePrefix);
                }
            }
            return(true);
        }
 public void MarkToRenderForInclusivePrefix(string prefix, bool searchOuterContext, IAncestralNamespaceContextProvider context)
 {
     MarkToRender(prefix, searchOuterContext, context, true);
 }