Hi Jim,
I would use a table to avoid a large switch statement for creating objects. Assuming you have an enum ElementType which defines the various classes and an interface IElement which is common to all objects that are created, you could use the following table. The order of the elements needs to match the enum:
static Func<IElement>[] Make = {
()=>{return new BitElement();},
()=>{return new StringElement();},
()=>{return new NumberElement();}
};
to create an instance you would use the following code:
ElementType type = ElementType.String;
IElement element = Make[(Int32)type]();
This would avoid reflection.
--
Christof