2 using System.Collections;
3 using System.Collections.Generic;
4 using System.Reflection;
5 using Tizen.NUI.Binding;
7 namespace Tizen.NUI.Xaml
9 internal class FillResourceDictionariesVisitor : IXamlNodeVisitor
11 public FillResourceDictionariesVisitor(HydrationContext context)
16 HydrationContext Context { get; }
17 Dictionary<INode, object> Values => Context.Values;
19 public TreeVisitingMode VisitingMode => TreeVisitingMode.TopDown;
20 public bool StopOnDataTemplate => true;
21 public bool StopOnResourceDictionary => false;
22 public bool VisitNodeOnDataTemplate => false;
24 public bool IsResourceDictionary(ElementNode node) => typeof(ResourceDictionary).IsAssignableFrom(Context.Types[node]);
26 public void Visit(ValueNode node, INode parentNode)
28 if (!typeof(ResourceDictionary).IsAssignableFrom(Context.Types[((IElementNode)parentNode)]))
31 node.Accept(new ApplyPropertiesVisitor(Context, stopOnResourceDictionary: false), parentNode);
34 public void Visit(MarkupNode node, INode parentNode)
38 public void Visit(ElementNode node, INode parentNode)
40 var value = Values[node];
43 if (typeof(ResourceDictionary).IsAssignableFrom(Context.Types[node]) && ApplyPropertiesVisitor.TryGetPropertyName(node, parentNode, out propertyName))
45 if ((propertyName.LocalName == "Resources" ||
46 propertyName.LocalName.EndsWith(".Resources", StringComparison.Ordinal)) && value is ResourceDictionary)
48 var source = Values[parentNode];
49 ApplyPropertiesVisitor.SetPropertyValue(source, propertyName, value, Context.RootElement, node, Context, node);
54 //Only proceed further if the node is a keyless RD
55 if (parentNode is IElementNode
56 && typeof(ResourceDictionary).IsAssignableFrom(Context.Types[((IElementNode)parentNode)])
57 && !((IElementNode)parentNode).Properties.ContainsKey(XmlName.xKey))
58 node.Accept(new ApplyPropertiesVisitor(Context, stopOnResourceDictionary: false), parentNode);
59 else if (parentNode is ListNode
60 && typeof(ResourceDictionary).IsAssignableFrom(Context.Types[((IElementNode)parentNode.Parent)])
61 && !((IElementNode)parentNode.Parent).Properties.ContainsKey(XmlName.xKey))
62 node.Accept(new ApplyPropertiesVisitor(Context, stopOnResourceDictionary: false), parentNode);
65 public void Visit(RootNode node, INode parentNode)
69 public void Visit(ListNode node, INode parentNode)
73 public bool SkipChildren(INode node, INode parentNode)
75 var enode = node as ElementNode;
78 if (parentNode is IElementNode
79 && typeof(ResourceDictionary).IsAssignableFrom(Context.Types[((IElementNode)parentNode)])
80 && !((IElementNode)parentNode).Properties.ContainsKey(XmlName.xKey))
82 if (parentNode is ListNode
83 && typeof(ResourceDictionary).IsAssignableFrom(Context.Types[((IElementNode)parentNode.Parent)])
84 && !((IElementNode)parentNode.Parent).Properties.ContainsKey(XmlName.xKey))