示例#1
0
 public static DocumentCompositeNode FindResource(DocumentNode key, DocumentCompositeNode resourcesCollection, int numberOfChildrenToSearch)
 {
     if (resourcesCollection != null && resourcesCollection.SupportsChildren)
     {
         IList <DocumentNode> children = resourcesCollection.Children;
         if (numberOfChildrenToSearch < 0)
         {
             numberOfChildrenToSearch = children.Count;
         }
         for (int i = 0; i < numberOfChildrenToSearch; i++)
         {
             DocumentCompositeNode item = children[i] as DocumentCompositeNode;
             if (item != null)
             {
                 DocumentNode resourceEntryKey = ResourceNodeHelper.GetResourceEntryKey(item);
                 if (resourceEntryKey == null)
                 {
                     DocumentCompositeNode documentCompositeNode = item.Properties[KnownProperties.DictionaryEntryValueProperty] as DocumentCompositeNode;
                     if (documentCompositeNode != null)
                     {
                         resourceEntryKey = ResourceSite.GetImplicitKey(documentCompositeNode);
                     }
                 }
                 if (resourceEntryKey != null && resourceEntryKey.Equals(key))
                 {
                     return(item);
                 }
             }
         }
     }
     return(null);
 }
示例#2
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);
        }
示例#3
0
        public static DocumentNode GetResourceKey(DocumentCompositeNode node)
        {
            IPropertyId resourceProperty = ResourceNodeHelper.GetResourceProperty(node);

            if (resourceProperty == null)
            {
                return(null);
            }
            return(node.Properties[resourceProperty]);
        }
示例#4
0
        private DocumentNode EvaluateResourceAtSpecificNode(DocumentNode node, DocumentNode keyNode, ICollection <DocumentCompositeNode> resourcesHostNodePath, ICollection <IDocumentRoot> relatedRoots, ICollection <string> warnings)
        {
            ISupportsResources resourcesCollection = ResourceNodeHelper.GetResourcesCollection(node);

            if (resourcesCollection == null)
            {
                return(null);
            }
            ResourceSite resourceSite = new ResourceSite(node.Context, resourcesCollection);

            return(this.EvaluateResourceAtSpecificSite(resourceSite, keyNode, resourcesHostNodePath, relatedRoots, -1, warnings));
        }
示例#5
0
        private static bool SearchForAnimationsInResources(DocumentCompositeNode elementNode, DocumentNode pathNameNode)
        {
            bool flag;
            DocumentCompositeNode resources           = null;
            ISupportsResources    resourcesCollection = ResourceNodeHelper.GetResourcesCollection(elementNode);

            if (resourcesCollection != null)
            {
                resources = resourcesCollection.Resources;
            }
            if (resources != null)
            {
                using (IEnumerator <DocumentNode> enumerator = resources.ChildNodes.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        DocumentCompositeNode current = enumerator.Current as DocumentCompositeNode;
                        if (current == null)
                        {
                            continue;
                        }
                        DocumentNode item = current.Properties[KnownProperties.DictionaryEntryValueProperty];
                        if (item == null || !PlatformTypes.Storyboard.IsAssignableFrom(item.Type))
                        {
                            continue;
                        }
                        using (IEnumerator <DocumentNode> enumerator1 = item.FindPointAnimationDescendantNodes().GetEnumerator())
                        {
                            while (enumerator1.MoveNext())
                            {
                                if (!PathGeometrySerializationHelper.DoesAnimationTargetPath(pathNameNode, enumerator1.Current))
                                {
                                    continue;
                                }
                                flag = true;
                                return(flag);
                            }
                        }
                    }
                    return(false);
                }
                return(flag);
            }
            return(false);
        }
示例#6
0
        public DocumentCompositeNode CreateResource(DocumentNode keyNode, DocumentNode valueNode, int index)
        {
            this.EnsureResourceCollection();
            DocumentCompositeNode documentCompositeNode = this.documentContext.CreateNode(PlatformTypes.DictionaryEntry);

            if (keyNode != null)
            {
                ResourceNodeHelper.SetResourceEntryKey(documentCompositeNode, keyNode);
            }
            documentCompositeNode.Properties[KnownProperties.DictionaryEntryValueProperty] = valueNode;
            IList <DocumentNode> children = this.resourcesHost.Resources.Children;

            if (index < 0)
            {
                index = children.Count;
            }
            children.Insert(index, documentCompositeNode);
            return(documentCompositeNode);
        }
示例#7
0
 private static void FindReferencedDictionariesInternal(DocumentCompositeNode resourceDictionaryNode, HashSet <Uri> dictionaries)
 {
     if (resourceDictionaryNode != null)
     {
         DocumentCompositeNode item = resourceDictionaryNode.Properties[KnownProperties.ResourceDictionaryMergedDictionariesProperty] as DocumentCompositeNode;
         if (item != null)
         {
             for (int i = 0; i < item.Children.Count; i++)
             {
                 DocumentCompositeNode documentCompositeNode = item.Children[i] as DocumentCompositeNode;
                 if (documentCompositeNode != null)
                 {
                     ResourceNodeHelper.FindReferencedDictionaryFromSource(documentCompositeNode, dictionaries);
                 }
             }
         }
         ResourceNodeHelper.FindReferencedDictionaryFromSource(resourceDictionaryNode, dictionaries);
     }
 }
示例#8
0
        public static IEnumerable <Uri> FindReferencedDictionaries(DocumentCompositeNode node)
        {
            HashSet <Uri> uris = new HashSet <Uri>();
            IPropertyId   resourcesProperty = node.Type.Metadata.ResourcesProperty;

            if (resourcesProperty != null)
            {
                DocumentCompositeNode item = node.Properties[resourcesProperty] as DocumentCompositeNode;
                if (item != null)
                {
                    node = item;
                }
            }
            if (PlatformTypes.ResourceDictionary.IsAssignableFrom(node.Type))
            {
                ResourceNodeHelper.FindReferencedDictionariesInternal(node, uris);
            }
            return(uris);
        }
示例#9
0
        private static void FindReferencedDictionaryFromSource(DocumentCompositeNode resourceDictionaryNode, HashSet <Uri> dictionaries)
        {
            DocumentCompositeNode rootNode;
            Uri uriValue = resourceDictionaryNode.GetUriValue(KnownProperties.ResourceDictionarySourceProperty);

            if (uriValue != null)
            {
                uriValue = resourceDictionaryNode.Context.MakeDesignTimeUri(uriValue);
                if (uriValue != null && uriValue.IsAbsoluteUri && !dictionaries.Contains(uriValue))
                {
                    dictionaries.Add(uriValue);
                    DocumentCompositeNode documentCompositeNode = null;
                    IDocumentRoot         documentRoot          = null;
                    try
                    {
                        documentRoot = resourceDictionaryNode.Context.GetDocumentRoot(uriValue.OriginalString);
                        if (documentRoot != null)
                        {
                            if (documentRoot.IsEditable)
                            {
                                rootNode = documentRoot.RootNode as DocumentCompositeNode;
                            }
                            else
                            {
                                rootNode = null;
                            }
                            documentCompositeNode = rootNode;
                        }
                    }
                    catch (IOException oException)
                    {
                    }
                    catch (NotSupportedException notSupportedException)
                    {
                    }
                    if (documentCompositeNode != null && PlatformTypes.ResourceDictionary.IsAssignableFrom(documentCompositeNode.Type))
                    {
                        ResourceNodeHelper.FindReferencedDictionariesInternal(documentCompositeNode, dictionaries);
                    }
                }
            }
        }
示例#10
0
        private SerializedFormat ShouldSerializeProperty(XamlSerializerContext serializerContext, DocumentCompositeNode parentNode, IPropertyId propertyKey, DocumentNode valueNode, out bool useElementForOuterMostMarkupExtension)
        {
            bool             flag;
            SerializedFormat serializedFormat;

            useElementForOuterMostMarkupExtension = false;
            DocumentCompositeNode documentCompositeNode = valueNode as DocumentCompositeNode;
            DocumentPrimitiveNode documentPrimitiveNode = valueNode as DocumentPrimitiveNode;
            IProperty             valueProperty         = valueNode.GetValueProperty();

            if (valueProperty != null)
            {
                if (valueProperty.MemberType != MemberType.DesignTimeProperty && !this.ShouldSerialize(serializerContext, valueNode))
                {
                    return(SerializedFormat.DoNotSerialize);
                }
                if (valueProperty.MemberType == MemberType.DesignTimeProperty)
                {
                    bool flag1 = true;
                    if (!valueProperty.ShouldSerialize)
                    {
                        flag1 = this.ShouldSerializeDesignTimeProperty(valueProperty);
                    }
                    if (!flag1)
                    {
                        return(SerializedFormat.DoNotSerialize);
                    }
                }
                if (!KnownProperties.SetterTargetNameProperty.Equals(valueProperty))
                {
                    if (parentNode.Type.Metadata.IsNameProperty(valueProperty))
                    {
                        string valueAsString = DocumentPrimitiveNode.GetValueAsString(valueNode);
                        if (valueAsString != null)
                        {
                            if (valueAsString.StartsWith("~", StringComparison.Ordinal) && serializerContext.InStyleOrTemplate)
                            {
                                return(SerializedFormat.DoNotSerialize);
                            }
                            if (valueAsString.Length == 0)
                            {
                                return(SerializedFormat.DoNotSerialize);
                            }
                        }
                        return(SerializedFormat.ComplexString);
                    }
                    if (DesignTimeProperties.UidProperty.Equals(valueProperty))
                    {
                        return(SerializedFormat.ComplexString);
                    }
                    if (KnownProperties.FrameworkContentElementResourcesProperty.Equals(valueProperty))
                    {
                        if (documentCompositeNode != null && PlatformTypes.ResourceDictionary.IsAssignableFrom(documentCompositeNode.Type) && documentCompositeNode.SupportsChildren && documentCompositeNode.Children.Count == 0)
                        {
                            return(SerializedFormat.DoNotSerialize);
                        }
                    }
                    else if (!PlatformTypes.Style.IsAssignableFrom(valueProperty.PropertyType))
                    {
                        DependencyPropertyReferenceStep dependencyPropertyReferenceStep = valueProperty as DependencyPropertyReferenceStep;
                        if (dependencyPropertyReferenceStep != null && dependencyPropertyReferenceStep.IsAttachable && !DefaultXamlSerializerFilter.IsTypeSerializable(serializerContext.TypeResolver, valueProperty.DeclaringType) && dependencyPropertyReferenceStep.MemberType != MemberType.DesignTimeProperty)
                        {
                            return(SerializedFormat.DoNotSerialize);
                        }
                    }
                    else if (documentCompositeNode != null)
                    {
                        if (documentCompositeNode.GetValue <bool>(DesignTimeProperties.IsDefaultStyleProperty))
                        {
                            return(SerializedFormat.DoNotSerialize);
                        }
                    }
                    else if (documentPrimitiveNode != null && documentPrimitiveNode.Value is DocumentNodeReferenceValue)
                    {
                        return(SerializedFormat.DoNotSerialize);
                    }
                }
                else
                {
                    string str = DocumentPrimitiveNode.GetValueAsString(valueNode);
                    if (str != null && str == "~Self")
                    {
                        return(SerializedFormat.DoNotSerialize);
                    }
                }
            }
            IType type = valueNode.Type;

            if (PlatformTypes.XData.Equals(type))
            {
                return(SerializedFormat.Element);
            }
            if (PlatformTypes.StaticResource.IsAssignableFrom(type) && documentCompositeNode != null && ResourceNodeHelper.GetResourceKey(documentCompositeNode) != null)
            {
                DocumentCompositeNode parent = documentCompositeNode.Parent;
                while (parent != null && parent.Type.IsExpression)
                {
                    parent = parent.Parent;
                }
                if (parent != null)
                {
                    IPropertyId resourcesProperty = parent.Type.Metadata.ResourcesProperty;
                    if (resourcesProperty != null)
                    {
                        DocumentCompositeNode item = parent.Properties[resourcesProperty] as DocumentCompositeNode;
                        if (item != null && PlatformTypes.ResourceDictionary.IsAssignableFrom(item.Type))
                        {
                            useElementForOuterMostMarkupExtension = true;
                            return(SerializedFormat.ComplexString);
                        }
                    }
                }
            }
            if (type.IsExpression)
            {
                if (documentCompositeNode != null)
                {
                    using (IEnumerator <KeyValuePair <IProperty, DocumentNode> > enumerator = documentCompositeNode.Properties.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            KeyValuePair <IProperty, DocumentNode> current = enumerator.Current;
                            switch (this.ShouldSerializeProperty(serializerContext, documentCompositeNode, current.Key, current.Value, out flag))
                            {
                            case SerializedFormat.SimpleString:
                            {
                                continue;
                            }

                            case SerializedFormat.ComplexString:
                            {
                                if (current.Value.Type.IsExpression)
                                {
                                    if (!flag)
                                    {
                                        continue;
                                    }
                                    useElementForOuterMostMarkupExtension = true;
                                    continue;
                                }
                                else
                                {
                                    serializedFormat = SerializedFormat.Element;
                                    return(serializedFormat);
                                }
                            }
                            }
                            serializedFormat = SerializedFormat.Element;
                            return(serializedFormat);
                        }
                        return(SerializedFormat.ComplexString);
                    }
                    return(serializedFormat);
                }
                return(SerializedFormat.ComplexString);
            }
            if (this.PropertyValueRequiresElement(valueProperty, valueNode.Type))
            {
                return(SerializedFormat.Element);
            }
            if (PlatformTypes.Uri.IsAssignableFrom(type))
            {
                return(SerializedFormat.ComplexString);
            }
            if (PlatformTypes.PropertyPath.IsAssignableFrom(type))
            {
                if (documentCompositeNode != null)
                {
                    if (DocumentPrimitiveNode.GetValueAsString(documentCompositeNode.Properties[KnownProperties.PropertyPathPathProperty]) != null)
                    {
                        return(SerializedFormat.SimpleString);
                    }
                    return(SerializedFormat.Element);
                }
            }
            else if (PlatformTypes.SolidColorBrush.IsAssignableFrom(type))
            {
                if (documentCompositeNode != null)
                {
                    if (documentCompositeNode.Properties.Count == 0)
                    {
                        return(SerializedFormat.SimpleString);
                    }
                    if (documentCompositeNode.Properties.Count == 1)
                    {
                        DocumentPrimitiveNode item1 = documentCompositeNode.Properties[KnownProperties.SolidColorBrushColorProperty] as DocumentPrimitiveNode;
                        if (item1 != null && PlatformTypes.Color.Equals(item1.Type))
                        {
                            return(SerializedFormat.SimpleString);
                        }
                    }
                    return(SerializedFormat.Element);
                }
            }
            else if (!PlatformTypes.Color.IsAssignableFrom(type))
            {
                if (PlatformTypes.PathGeometry.IsAssignableFrom(type))
                {
                    if (valueProperty == null || PlatformTypes.PathGeometry.IsAssignableFrom(valueProperty.PropertyType))
                    {
                        return(SerializedFormat.Element);
                    }
                    if (documentCompositeNode != null && !PathGeometrySerializationHelper.CanSerializeAsAttribute(documentCompositeNode))
                    {
                        return(SerializedFormat.Element);
                    }
                    return(SerializedFormat.ComplexString);
                }
                if (PlatformTypes.PathFigureCollection.IsAssignableFrom(type))
                {
                    if (documentCompositeNode != null && !PathGeometrySerializationHelper.CanSerializeAsAttribute(documentCompositeNode))
                    {
                        return(SerializedFormat.Element);
                    }
                    return(SerializedFormat.ComplexString);
                }
                if (PlatformTypes.DoubleCollection.IsAssignableFrom(type))
                {
                    if (documentCompositeNode != null && PointSerializationHelper.SerializeDoubleCollectionAsAttribute(documentCompositeNode) == null)
                    {
                        return(SerializedFormat.Element);
                    }
                    return(SerializedFormat.ComplexString);
                }
            }
            else if (documentCompositeNode == null && valueNode.Parent != null && valueNode.IsProperty)
            {
                return(SerializedFormat.SimpleString);
            }
            if (documentPrimitiveNode != null && documentPrimitiveNode.Value == null)
            {
                return(SerializedFormat.SimpleString);
            }
            if (XamlSerializerContext.IsXmlElement(valueNode))
            {
                return(SerializedFormat.Element);
            }
            if (documentPrimitiveNode != null)
            {
                if (documentPrimitiveNode.Value is DocumentNodeStringValue)
                {
                    return(SerializedFormat.SimpleString);
                }
                if (documentPrimitiveNode.Value is DocumentNodeMemberValue)
                {
                    return(SerializedFormat.SimpleString);
                }
            }
            if (documentCompositeNode == null)
            {
                return(SerializedFormat.ComplexString);
            }
            return(SerializedFormat.Element);
        }
示例#11
0
 public ResourceSite(DocumentNode resourcesHost) : this(resourcesHost.Context, ResourceNodeHelper.GetResourcesCollection(resourcesHost))
 {
 }
示例#12
0
        public static void SetResourceKey(DocumentCompositeNode node, DocumentNode valueNode)
        {
            IPropertyId resourceProperty = ResourceNodeHelper.GetResourceProperty(node);

            node.Properties[resourceProperty] = valueNode;
        }
示例#13
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);
        }