Exemplo n.º 1
0
        public bool IsAncestorOf(DocumentNodePath other)
        {
            if (other == this)
            {
                return(true);
            }
            if (other == null)
            {
                return(false);
            }
            int count = this.nodes.Count;

            if (count <= other.nodes.Count)
            {
                int num = 0;
                while (num < count && this.nodes[num].Equals(other.nodes[num]))
                {
                    num++;
                }
                if (num >= count)
                {
                    return(true);
                }
                if (this.nodes[num].Container == other.nodes[num].Container && this.nodes[num].Target.IsAncestorOf(other.nodes[num].Target))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        public DocumentNodePath GetPathInSubContainer(IProperty propertyKey, DocumentNode newContainer)
        {
            DocumentNodePath subpath = this.GetSubpath(this.nodes.Count);

            subpath.nodes.Add(new NodePathEntry(propertyKey, newContainer, newContainer));
            return(subpath);
        }
Exemplo n.º 3
0
        private DocumentNodePath GetSubpath(int numberOfEntries)
        {
            DocumentNodePath documentNodePath = new DocumentNodePath();

            documentNodePath.AppendNodePathEntries(this, numberOfEntries);
            return(documentNodePath);
        }
Exemplo n.º 4
0
        public override bool Equals(object obj)
        {
            bool flag;

            if (obj != this)
            {
                DocumentNodePath documentNodePath = obj as DocumentNodePath;
                if (documentNodePath == null || documentNodePath.nodes.Count != this.nodes.Count)
                {
                    flag = false;
                }
                else
                {
                    flag = true;
                    int count = this.nodes.Count - 1;
                    while (count >= 0)
                    {
                        if (this.nodes[count].Equals(documentNodePath.nodes[count]))
                        {
                            count--;
                        }
                        else
                        {
                            flag = false;
                            return(flag);
                        }
                    }
                }
            }
            else
            {
                flag = true;
            }
            return(flag);
        }
Exemplo n.º 5
0
        public DocumentNode EvaluateTemplateBinding(DocumentNodePath nodePath, DocumentCompositeNode templateBindingNode)
        {
            DocumentNode documentNode = null;
            DependencyPropertyReferenceStep member = null;
            DocumentPrimitiveNode           item   = templateBindingNode.Properties[KnownProperties.TemplateBindingPropertyProperty] as DocumentPrimitiveNode;

            if (item != null)
            {
                DocumentNodeMemberValue value = item.Value as DocumentNodeMemberValue;
                if (value != null)
                {
                    member = value.Member as DependencyPropertyReferenceStep;
                }
            }
            if (member != null)
            {
                DocumentNodePath containerOwnerPath = nodePath.GetContainerOwnerPath();
                if (containerOwnerPath != null)
                {
                    documentNode = this.EvaluateProperty(containerOwnerPath, member);
                    if (documentNode == null)
                    {
                        DocumentCompositeNode containerNode = nodePath.ContainerNode as DocumentCompositeNode;
                        documentNode = this.EvaluateProperty(nodePath.GetPathInContainer(containerNode), member);
                    }
                }
            }
            return(documentNode);
        }
Exemplo n.º 6
0
        public DocumentNode EvaluateExpression(DocumentNodePath context, DocumentNode expression)
        {
            DocumentCompositeNode documentCompositeNode  = expression as DocumentCompositeNode;
            DocumentCompositeNode documentCompositeNode1 = documentCompositeNode;

            if (documentCompositeNode == null)
            {
                DocumentPrimitiveNode documentPrimitiveNode  = expression as DocumentPrimitiveNode;
                DocumentPrimitiveNode documentPrimitiveNode1 = documentPrimitiveNode;
                if (documentPrimitiveNode != null)
                {
                    DocumentNodeReferenceValue value = documentPrimitiveNode1.Value as DocumentNodeReferenceValue;
                    if (value != null)
                    {
                        return(value.Value);
                    }
                }
            }
            else
            {
                if (DocumentNodeUtilities.IsTemplateBinding(documentCompositeNode1))
                {
                    return(this.EvaluateTemplateBinding(context, documentCompositeNode1));
                }
                if (documentCompositeNode1.Type.IsResource)
                {
                    DocumentNode resourceKey = ResourceNodeHelper.GetResourceKey(documentCompositeNode1);
                    if (resourceKey != null)
                    {
                        return(this.EvaluateResource(context, ResourceNodeHelper.GetResourceType(documentCompositeNode1), resourceKey));
                    }
                }
            }
            return(expression);
        }
Exemplo n.º 7
0
        public DocumentNodePath GetPathInContainer(DocumentNode node)
        {
            DocumentNodePath subpath = this.GetSubpath(this.nodes.Count - 1);
            NodePathEntry    item    = this.nodes[this.nodes.Count - 1];

            subpath.nodes.Add(new NodePathEntry(item.PropertyKey, item.Container, node, item.ViewKey));
            return(subpath);
        }
Exemplo n.º 8
0
        public DocumentNodePath GetContainerOwnerPath()
        {
            DocumentNodePath subpath = null;

            if (this.nodes.Count > 1)
            {
                subpath = this.GetSubpath(this.nodes.Count - 1);
            }
            return(subpath);
        }
Exemplo n.º 9
0
 private void AppendNodePathEntries(DocumentNodePath source, int numberOfEntries)
 {
     if (numberOfEntries > source.nodes.Count)
     {
         throw new ArgumentException(ExceptionStringTable.DocumentNodePathNumberOfNodesExceeded, "numberOfEntries");
     }
     for (int i = 0; i < numberOfEntries; i++)
     {
         this.nodes.Add(source.nodes[i]);
     }
 }
Exemplo n.º 10
0
        public DocumentNodePath GetParent()
        {
            DocumentNodePath containerOwnerPath = null;
            DocumentNode     node = this.Node;

            if (node == this.ContainerNode)
            {
                containerOwnerPath = this.GetContainerOwnerPath();
            }
            else if (node.Parent != null)
            {
                containerOwnerPath = this.GetPathInContainer(node.Parent);
            }
            return(containerOwnerPath);
        }
Exemplo n.º 11
0
        public DocumentNode EvaluateResourceAndCollectionPath(DocumentNodePath nodePath, ResourceReferenceType referenceType, DocumentNode keyNode, ICollection <DocumentCompositeNode> resourcesHostNodePath, ICollection <IDocumentRoot> relatedRoots, ICollection <string> warnings, out bool invalidForwardReference)
        {
            Uri           uri;
            DocumentNode  documentNode;
            IDocumentRoot applicationRoot;
            IDocumentRoot documentRoot = nodePath.RootNode.DocumentRoot;

            if (this.documentRootResolver != null)
            {
                applicationRoot = this.documentRootResolver.ApplicationRoot;
            }
            else
            {
                applicationRoot = null;
            }
            IDocumentRoot documentRoot1 = applicationRoot;
            bool          flag          = (documentRoot1 == null ? false : documentRoot1.RootNode != null);
            IDocumentRoot documentRoot2 = null;

            invalidForwardReference = false;
            if (referenceType != ResourceReferenceType.Static)
            {
                DocumentNode node = nodePath.Node;
                while (node != null)
                {
                    if (flag && node.DocumentRoot != null && node == node.DocumentRoot.RootNode && PlatformTypes.ResourceDictionary.IsAssignableFrom(node.Type))
                    {
                        string documentUrl             = node.Context.DocumentUrl;
                        DocumentCompositeNode rootNode = documentRoot1.RootNode as DocumentCompositeNode;
                        if (rootNode != null && Uri.TryCreate(documentUrl, UriKind.Absolute, out uri) && ResourceNodeHelper.FindReferencedDictionaries(rootNode).Contains <Uri>(uri))
                        {
                            documentRoot2 = node.DocumentRoot;
                            break;
                        }
                    }
                    DocumentNode documentNode1 = this.EvaluateResourceAtSpecificNode(node, keyNode, resourcesHostNodePath, relatedRoots, warnings);
                    if (documentNode1 != null)
                    {
                        return(documentNode1);
                    }
                    node = node.Parent;
                    if (node == null || nodePath == null)
                    {
                        continue;
                    }
                    DocumentNode containerNode  = nodePath.ContainerNode;
                    DocumentNode styleForSetter = ExpressionEvaluator.GetStyleForSetter(node);
                    if (styleForSetter == null || styleForSetter != containerNode)
                    {
                        styleForSetter = ExpressionEvaluator.GetStyleForResourceEntry(node);
                        if (styleForSetter == null)
                        {
                            if (node != containerNode)
                            {
                                continue;
                            }
                            nodePath = null;
                        }
                        else
                        {
                            if (styleForSetter == containerNode)
                            {
                                nodePath = null;
                            }
                            node = styleForSetter.Parent;
                        }
                    }
                    else
                    {
                        nodePath = nodePath.GetContainerOwnerPath();
                        if (nodePath == null)
                        {
                            continue;
                        }
                        node = nodePath.Node;
                    }
                }
            }
            else
            {
                DocumentNode documentNode2 = null;
                for (DocumentNode i = nodePath.Node; i != null; i = i.Parent)
                {
                    ISupportsResources resourcesCollection = ResourceNodeHelper.GetResourcesCollection(i);
                    if (resourcesCollection != null)
                    {
                        ResourceSite resourceSite  = new ResourceSite(i.Context, resourcesCollection);
                        DocumentNode documentNode3 = null;
                        if (ResourceNodeHelper.IsResourceDictionary(resourcesCollection))
                        {
                            int siteChildIndex = -1;
                            if (documentNode2 != null)
                            {
                                siteChildIndex = documentNode2.SiteChildIndex;
                            }
                            documentNode3 = this.EvaluateResourceAtSpecificSite(resourceSite, keyNode, resourcesHostNodePath, relatedRoots, siteChildIndex, warnings);
                        }
                        else if (ResourceNodeHelper.IsResourceContainer(resourcesCollection, documentNode2))
                        {
                            documentNode3 = this.EvaluateResourceAtSpecificSite(resourceSite, keyNode, resourcesHostNodePath, relatedRoots, -1, warnings);
                        }
                        if (documentNode3 != null)
                        {
                            if (keyNode != null && keyNode.Parent != null && keyNode.Parent.Parent == i)
                            {
                                ITextRange nodeSpan  = DocumentNodeHelper.GetNodeSpan(keyNode.Parent);
                                ITextRange textRange = DocumentNodeHelper.GetNodeSpan(documentNode3);
                                if (!TextRange.IsNull(textRange) && !TextRange.IsNull(nodeSpan) && nodeSpan.Offset < textRange.Offset)
                                {
                                    documentNode3           = null;
                                    invalidForwardReference = true;
                                }
                            }
                            if (documentNode3 != null)
                            {
                                return(documentNode3);
                            }
                        }
                    }
                    documentNode2 = i;
                }
            }
            if (flag)
            {
                DocumentNode documentNode4 = this.EvaluateResourceAtSpecificNode(documentRoot1.RootNode, keyNode, resourcesHostNodePath, relatedRoots, warnings);
                if (documentNode4 != null)
                {
                    if (relatedRoots != null && documentNode4.DocumentRoot != documentRoot2)
                    {
                        relatedRoots.Add(documentRoot1);
                    }
                    return(documentNode4);
                }
            }
            if (documentRoot != null)
            {
                using (IEnumerator <IDocumentRoot> enumerator = documentRoot.DesignTimeResources.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        IDocumentRoot current       = enumerator.Current;
                        DocumentNode  documentNode5 = this.EvaluateResourceAtSpecificNode(current.RootNode, keyNode, resourcesHostNodePath, relatedRoots, warnings);
                        if (documentNode5 == null)
                        {
                            continue;
                        }
                        if (relatedRoots != null && documentNode5.DocumentRoot != documentRoot2)
                        {
                            relatedRoots.Add(current);
                        }
                        documentNode = documentNode5;
                        return(documentNode);
                    }
                    return(null);
                }
                return(documentNode);
            }
            return(null);
        }
Exemplo n.º 12
0
        public DocumentNode EvaluateResourceAndCollectionPath(DocumentNodePath nodePath, ResourceReferenceType referenceType, DocumentNode keyNode, ICollection <DocumentCompositeNode> resourcesHostNodePath, ICollection <IDocumentRoot> relatedRoots, ICollection <string> warnings)
        {
            bool flag;

            return(this.EvaluateResourceAndCollectionPath(nodePath, referenceType, keyNode, resourcesHostNodePath, relatedRoots, warnings, out flag));
        }
Exemplo n.º 13
0
 public DocumentNode EvaluateResource(DocumentNodePath nodePath, ResourceReferenceType referenceType, DocumentNode keyNode)
 {
     return(this.EvaluateResourceAndCollectionPath(nodePath, referenceType, keyNode, null, null, null));
 }
Exemplo n.º 14
0
 public DocumentNode EvaluateProperty(DocumentNodePath nodePath, IPropertyId propertyKey)
 {
     return(this.EvaluateExpression(nodePath, ((DocumentCompositeNode)nodePath.Node).Properties[propertyKey]));
 }
Exemplo n.º 15
0
        public static DocumentNode EvaluateExpression(DocumentNode expression)
        {
            DocumentNodePath documentNodePath = new DocumentNodePath(expression.DocumentRoot.RootNode, expression);

            return((new ExpressionEvaluator(expression.Context)).EvaluateExpression(documentNodePath, expression));
        }