I have a method that returns a List<T>
of child controls that looks like this:
void GetAllControlsOfType<T>(List<T> lst, Control parent) where T:class
{
if (parent.GetType() == typeof(T))
lst.Add(parent as T);
foreach (Control ch in parent.Controls)
this.GetAllControlsOfType<T>(lst, ch);
}
But I have to use it like this:
List<WebControl> foo = new List<WebControl>();
GetAllControlsOfType<WebControl>(foo, this); //this = webpage instance
Surely there is some c# magic that will allow me to write a method that I can call like this:
List<WebControl> foo = GetAllControlsOfType<WebControl>(this);