summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Xaml/XamlNodeVisitor.cs
blob: 874a5fbd41960ef0d2feba4257825c73ccf9bd78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
´╗┐using System;

namespace Xamarin.Forms.Xaml
{
	interface IXamlNodeVisitor
	{
		TreeVisitingMode VisitingMode { get; }
		bool StopOnDataTemplate { get; }
		bool VisitNodeOnDataTemplate { get; }
		bool StopOnResourceDictionary { get; }

		void Visit(ValueNode node, INode parentNode);
		void Visit(MarkupNode node, INode parentNode);
		void Visit(ElementNode node, INode parentNode);
		void Visit(RootNode node, INode parentNode);
		void Visit(ListNode node, INode parentNode);
	}

	enum TreeVisitingMode {
		TopDown,
		BottomUp
	}

	class XamlNodeVisitor : IXamlNodeVisitor
	{
		readonly Action<INode, INode> action;

		public XamlNodeVisitor(Action<INode, INode> action, TreeVisitingMode visitingMode = TreeVisitingMode.TopDown, bool stopOnDataTemplate = false, bool visitNodeOnDataTemplate = true)
		{
			this.action = action;
			VisitingMode = visitingMode;
			StopOnDataTemplate = stopOnDataTemplate;
			VisitNodeOnDataTemplate = visitNodeOnDataTemplate;
		}

		public TreeVisitingMode VisitingMode { get; }
		public bool StopOnDataTemplate { get; }
		public bool StopOnResourceDictionary { get; private set; }
		public bool VisitNodeOnDataTemplate { get; }

		public void Visit(ValueNode node, INode parentNode)
		{
			action(node, parentNode);
		}

		public void Visit(MarkupNode node, INode parentNode)
		{
			action(node, parentNode);
		}

		public void Visit(ElementNode node, INode parentNode)
		{
			action(node, parentNode);
		}

		public void Visit(RootNode node, INode parentNode)
		{
			action(node, parentNode);
		}

		public void Visit(ListNode node, INode parentNode)
		{
			action(node, parentNode);
		}
	}
}