internal static TRoot Replace <TRoot>(TRoot root, IEnumerable <PrtgNode> nodes, Func <PrtgNode, PrtgNode, PrtgNode> computeReplacementNode) where TRoot : PrtgNode { if (computeReplacementNode == null) { return(root); } var replacer = new PrtgNodeReplacer(nodes, computeReplacementNode); return((TRoot)replacer.Visit(root)); }
/// <summary> /// Creates a new <see cref="PrtgNode"/> with multiple descendant <see cref="PrtgNode"/> objects replaced according to a callback function. /// </summary> /// <typeparam name="TRoot">The type of the root node.</typeparam> /// <param name="root">The node to replace descendant nodes of.</param> /// <param name="nodes">The existing nodes to be replaced.</param> /// <param name="computeReplacementNode">A function the computes the replacement node.<para/> /// If the descendants of a node to be replaced were was also replaced, this function is passed /// the original node and its calculated replacement reflecting the changes to its descendants.<para/> /// Otherwise, both arguments to this function will be the original node.</param> /// <returns>If <paramref name="computeReplacementNode"/> was null, the original node. Otherwise /// a new node with all replacements made.</returns> public static TRoot ReplaceNodes <TRoot>(this TRoot root, IEnumerable <PrtgNode> nodes, Func <PrtgNode, PrtgNode, PrtgNode> computeReplacementNode) where TRoot : PrtgNode { return(PrtgNodeReplacer.Replace(root, nodes, computeReplacementNode)); }