public static ISyntaxNodeViewModel Ancestor <T>(this ISyntaxNodeViewModel @this) { Type ancestorType = typeof(T); ISyntaxNodeViewModel ancestor = @this.Owner; while (ancestor != null) { if (ancestor.GetType() != ancestorType) { ancestor = ancestor.Owner; } else { break; } } return(ancestor); }