Posted 17 years ago
by Kelly Leahy
-
Software Architect,
Milliman
On the AstNodeBase class, might I request a FindNodeRecursive overload (or a FindDescendant method) that looks for a particular type of node?
It would be similar to FindAnscestor, except walking DOWN the tree instead of UP...
It would stop on the first "child" that is of the type requested (if any found).
My naive implementation is:But a faster implementation would walk the tree directly, of course, rather than walking down only to walk back up.
Thanks!
[Modified at 05/09/2007 01:05 PM]
It would be similar to FindAnscestor, except walking DOWN the tree instead of UP...
It would stop on the first "child" that is of the type requested (if any found).
My naive implementation is:
public IAstNode FindDescendant(int offset, Type type)
{
IAstNode an = this.FindNodeRecursive(offset);
if (an == null || an.GetType() == type)
return an;
else
return an.FindAncestor(type);
}
Thanks!
[Modified at 05/09/2007 01:05 PM]
Kelly Leahy Software Architect Milliman, USA