private bool AdoptNodeByAncestor(BaseNode target, BaseNode node) { if (target != null && target.CanAdopt(node)) { target = target.Parent; // check if there is a Method node on the parent path while (target != null) { if (target is Nodes.Method) { return target.CanAdopt(node); } target = target.Parent; } return true; } return false; }