From 080f1697e97e13461ec6df4d31c8924d01257a1b Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Tue, 9 Apr 2019 01:47:48 +0300 Subject: MERGE --- .../Xml/ExtensionMethods.cs | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Xml/ExtensionMethods.cs (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Xml/ExtensionMethods.cs') diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Xml/ExtensionMethods.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Xml/ExtensionMethods.cs new file mode 100644 index 000000000..34664a23a --- /dev/null +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Editors/Xml/ExtensionMethods.cs @@ -0,0 +1,47 @@ +// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) +// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Collections.Specialized; +using System.Diagnostics; +using System.Linq; + +using Tango.Scripting.Editors.Document; + +namespace Tango.Scripting.Editors.Xml +{ + static class ExtensionMethods + { + // Copied from ICSharpCode.SharpDevelop.Dom.ExtensionMethods + /// + /// Converts a recursive data structure into a flat list. + /// + /// The root elements of the recursive data structure. + /// The function that gets the children of an element. + /// Iterator that enumerates the tree structure in preorder. + public static IEnumerable Flatten(this IEnumerable input, Func> recursion) + { + Stack> stack = new Stack>(); + try { + stack.Push(input.GetEnumerator()); + while (stack.Count > 0) { + while (stack.Peek().MoveNext()) { + T element = stack.Peek().Current; + yield return element; + IEnumerable children = recursion(element); + if (children != null) { + stack.Push(children.GetEnumerator()); + } + } + stack.Pop().Dispose(); + } + } finally { + while (stack.Count > 0) { + stack.Pop().Dispose(); + } + } + } + } +} -- cgit v1.3.1