My first question is, is it possible to specify a generic type as a parameter, secondly, is anything such as the pseudo code ive listed below possible?
I assume it will be using .net 4.0 and the dynamics modifier but i am more interested in a pre 4.0 solution.
public static void SomeMethod(List<T> l, Type type, Control samplecontrol)
{
l.Add((type)samplecontrol);
}
Edit:
Here is my solution...
public static void FindControlRecursive<T>(Control parent, List<T> l)
{
foreach (var ctrl in parent.Controls)
{
if (ctrl.GetType() == typeof(T))
l.Add((T)ctrl);
if (((Control)ctrl).Controls != null && ((Control)ctrl).Controls.Count > 0)
foreach (Control _ctrl in ((Control)ctrl).Controls)
FindControlRecursive<T>(_ctrl, l);
}
}