public static TRoot Replace <TRoot, TNode>(this TRoot root, TNode node, Func <TNode, TNode?> computeReplacement) where TNode : SourceNode where TRoot : SourceNode { var replacer = new NodeReplacer <TNode>(new[] { node }, computeReplacement); return((TRoot?)replacer.Visit(root) ?? throw new InvalidOperationException()); }
public static TRoot Remove <TRoot, TNode>(this TRoot root, TNode node) where TNode : SourceNode where TRoot : SourceNode { var replacer = new NodeReplacer <TNode>(new[] { node }, x => null); return((TRoot?)replacer.Visit(root) ?? throw new InvalidOperationException()); }
public static Expression Replace(Expression expression, Expression oldNode, Expression newNode) { var replacer = new NodeReplacer { oldNode = oldNode, newNode = newNode }; return(replacer.Visit(expression)); }