mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 13:15:07 +00:00
feat: Xml recursion methods allow cancelling recursion into child nodes
This commit is contained in:
@@ -115,7 +115,7 @@ namespace ICD.Common.Utils.Xml
|
|||||||
/// <param name="extends"></param>
|
/// <param name="extends"></param>
|
||||||
/// <param name="callback"></param>
|
/// <param name="callback"></param>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Recurse(this IcdXmlReader extends, Action<XmlRecursionEventArgs> callback)
|
public static void Recurse(this IcdXmlReader extends, Func<XmlRecursionEventArgs, bool> callback)
|
||||||
{
|
{
|
||||||
if (extends == null)
|
if (extends == null)
|
||||||
throw new ArgumentNullException("extends");
|
throw new ArgumentNullException("extends");
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ namespace ICD.Common.Utils.Xml
|
|||||||
/// <param name="xml"></param>
|
/// <param name="xml"></param>
|
||||||
/// <param name="callback"></param>
|
/// <param name="callback"></param>
|
||||||
[PublicAPI]
|
[PublicAPI]
|
||||||
public static void Recurse(string xml, Action<XmlRecursionEventArgs> callback)
|
public static void Recurse(string xml, Func<XmlRecursionEventArgs, bool> callback)
|
||||||
{
|
{
|
||||||
if (callback == null)
|
if (callback == null)
|
||||||
throw new ArgumentNullException("callback");
|
throw new ArgumentNullException("callback");
|
||||||
@@ -152,7 +152,7 @@ namespace ICD.Common.Utils.Xml
|
|||||||
/// <param name="xml"></param>
|
/// <param name="xml"></param>
|
||||||
/// <param name="path"></param>
|
/// <param name="path"></param>
|
||||||
/// <param name="callback"></param>
|
/// <param name="callback"></param>
|
||||||
private static void Recurse(string xml, Stack<string> path, Action<XmlRecursionEventArgs> callback)
|
private static void Recurse(string xml, Stack<string> path, Func<XmlRecursionEventArgs, bool> callback)
|
||||||
{
|
{
|
||||||
if (path == null)
|
if (path == null)
|
||||||
throw new ArgumentNullException("path");
|
throw new ArgumentNullException("path");
|
||||||
@@ -168,10 +168,11 @@ namespace ICD.Common.Utils.Xml
|
|||||||
path.Push(childReader.Name);
|
path.Push(childReader.Name);
|
||||||
string[] pathOutput = path.Reverse().ToArray(path.Count);
|
string[] pathOutput = path.Reverse().ToArray(path.Count);
|
||||||
|
|
||||||
callback(new XmlRecursionEventArgs(xml, pathOutput));
|
if (callback(new XmlRecursionEventArgs(xml, pathOutput)))
|
||||||
|
{
|
||||||
foreach (string child in childReader.GetChildElementsAsString())
|
foreach (string child in childReader.GetChildElementsAsString())
|
||||||
Recurse(child, path, callback);
|
Recurse(child, path, callback);
|
||||||
|
}
|
||||||
|
|
||||||
path.Pop();
|
path.Pop();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user