In Generics, types must be known compile-time, not run-time, and do not instance parameters (controltype is an instance of the System.String class). The suggestion from Guffa is very good, but you could still avoid having tons of switches in your code. Start from the fact that all your controls inherit from the System.Windows.Forms.Control class, which, I would say, contains about 95% of the properties of the built-in controls (Size, Font, Text, Position, Name, Visible, etc.). So, using reflection, you could, as suggested by Guffa, instanciate your controls in a way similar to the one below:
List<Control> controls = new List<Control>();
foreach (....)
{
Type myControlType = Type.ReflectionOnlyGetType(controltype, true, false);
ConstructorInfo myControlContructor = myControlType.GetConstructor(Type.EmtpyTypes); // Default
Control myControl = myControlContructor.Invoke(null);
controls.Add(myControl);
}
// It is more efficient to declare the variables outside the loop, though.
Then, set all the properties common to all controls, I think this would cover much of your cases. You will need some mechanism (maybe a flag from your database) to indicate properties that are not defined in the System.Windows.Forms.Control class. Hope this helps, Michel -------- "I say no to drugs, but they don't listen." - Marilyn Manson -- modified at 7:39 Friday 27th January, 2006