2020-05-19 03:56:25 +03:00
|
|
|
using System;
|
2016-03-22 23:02:25 +03:00
|
|
|
|
2020-05-19 03:56:25 +03:00
|
|
|
namespace System.Maui.Xaml
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
2017-01-25 16:47:27 +03:00
|
|
|
interface IXamlNodeVisitor
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
2017-01-25 16:47:27 +03:00
|
|
|
TreeVisitingMode VisitingMode { get; }
|
2016-03-22 23:02:25 +03:00
|
|
|
bool StopOnDataTemplate { get; }
|
2017-01-25 16:47:27 +03:00
|
|
|
bool VisitNodeOnDataTemplate { get; }
|
2016-03-22 23:02:25 +03:00
|
|
|
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);
|
2018-01-11 22:03:12 +03:00
|
|
|
bool SkipChildren(INode node, INode parentNode);
|
2018-04-20 06:50:47 +03:00
|
|
|
bool IsResourceDictionary(ElementNode node);
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
2017-01-25 16:47:27 +03:00
|
|
|
enum TreeVisitingMode {
|
|
|
|
TopDown,
|
|
|
|
BottomUp
|
|
|
|
}
|
|
|
|
|
|
|
|
class XamlNodeVisitor : IXamlNodeVisitor
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
|
|
|
readonly Action<INode, INode> action;
|
|
|
|
|
2017-01-25 16:47:27 +03:00
|
|
|
public XamlNodeVisitor(Action<INode, INode> action, TreeVisitingMode visitingMode = TreeVisitingMode.TopDown, bool stopOnDataTemplate = false, bool visitNodeOnDataTemplate = true)
|
2016-03-22 23:02:25 +03:00
|
|
|
{
|
|
|
|
this.action = action;
|
2017-01-25 16:47:27 +03:00
|
|
|
VisitingMode = visitingMode;
|
2016-03-22 23:02:25 +03:00
|
|
|
StopOnDataTemplate = stopOnDataTemplate;
|
2017-01-25 16:47:27 +03:00
|
|
|
VisitNodeOnDataTemplate = visitNodeOnDataTemplate;
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
|
|
|
|
2017-01-25 16:47:27 +03:00
|
|
|
public TreeVisitingMode VisitingMode { get; }
|
2016-03-22 23:02:25 +03:00
|
|
|
public bool StopOnDataTemplate { get; }
|
2017-09-25 09:52:03 +03:00
|
|
|
public bool StopOnResourceDictionary { get; }
|
2017-01-25 16:47:27 +03:00
|
|
|
public bool VisitNodeOnDataTemplate { get; }
|
2016-03-22 23:02:25 +03:00
|
|
|
|
2018-01-11 22:03:12 +03:00
|
|
|
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);
|
|
|
|
public bool SkipChildren(INode node, INode parentNode) => false;
|
2018-04-20 06:50:47 +03:00
|
|
|
public bool IsResourceDictionary(ElementNode node) => false;
|
2016-03-22 23:02:25 +03:00
|
|
|
}
|
2018-04-20 06:50:47 +03:00
|
|
|
}
|