/// <summary> /// Remove an inner element to this CppElement /// </summary> /// <param name = "element"></param> public void Remove(CppElement element) { element.Parent = null; if (Items != null) { Items.Remove(element); } }
/// <summary> /// Add an inner element to this CppElement /// </summary> /// <param name = "element"></param> public void Add(CppElement element) { if (element.Parent != null) { element.Parent.Remove(element); } element.Parent = this; GetSafeItems().Add(element); }
/// <summary> /// Add an inner element to this CppElement /// </summary> /// <param name = "element"></param> public void Add(CppElement element) { if (element.Parent != null) { element.Parent.Remove(element); } element.Parent = this; if (Items == null) { Items = new List <CppElement>(); } Items.Add(element); }
/// <summary> /// Finds the specified elements by regex. /// </summary> /// <typeparam name="T">The type of element to find</typeparam> /// <param name="currentNode">The current node in the search.</param> /// <param name="regex">The regex.</param> /// <param name="mode">The selection mode.</param> /// <returns>The selected elements.</returns> private IEnumerable <T> Find <T>(CppElement currentNode, Regex regex, SelectionMode mode) where T : CppElement { var path = currentNode.FullName; CppElement selectedElement; switch (mode) { case SelectionMode.MatchedElement: selectedElement = currentNode; break; case SelectionMode.Parent: selectedElement = currentNode.Parent; break; default: throw new ArgumentException("Invalid selection mode.", nameof(mode)); } if (path != null && (selectedElement is T cppElement) && regex.Match(path).Success) { yield return(cppElement); } if (currentNode == Root && CurrentContexts.Count != 0) { // Optimized version with context attributes foreach (var innerElement in currentNode.AllItems.Where(element => CurrentContexts.Contains(element.Name))) { foreach (var item in Find <T>(innerElement, regex, mode)) { yield return(item); } } } else { foreach (var innerElement in currentNode.AllItems) { foreach (var item in Find <T>(innerElement, regex, mode)) { yield return(item); } } } }
public CppElementFinder(CppElement root) { Root = root; }
/// <summary> /// Remove an inner element to this CppElement /// </summary> /// <param name = "element"></param> public void Remove(CppElement element) { element.Parent = null; GetSafeItems().Remove(element); }