Skip to content

Instantly share code, notes, and snippets.

@ChrisMissal
Created June 17, 2013 18:18
Show Gist options
  • Save ChrisMissal/5798972 to your computer and use it in GitHub Desktop.
Save ChrisMissal/5798972 to your computer and use it in GitHub Desktop.
Recursively fetch the first non-null ancestor.
public static T GetFarthestAncestor<T>(this T self, Func<T, T> ancestorSelector)
{
var parent = ancestorSelector(self);
return parent != null
? GetFarthestAncestor(parent, ancestorSelector)
: self;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment