Couldn\'t think of a better title so appologies..
I\'m trying to convert this method, which will retrieve all child controls of a form, to be an extension method as
The problem is that Concat
would want an IEnumerable<T>
as well - not an IEnumerable<Control>
. This should work though:
public static IEnumerable<T> GetAll<T>(this Control control) where T : class
{
var controls = control.Controls.Cast<Control>();
return controls.SelectMany(ctrl => GetAll<T>(ctrl))
.Concat(controls.OfType<T>()));
}