This isn’t legal:
public class MyBaseClass { public MyBaseClass() {} public MyBaseClass(object arg) {} } public void ThisIsANoNo<T>() where T : MyBaseClass { T foo = new T('whoops!'); }
In order to do this, you have to do some reflection on the type object for T or you have to use Activator.CreateInstance. Both are pretty nasty. Is there a better way?
You can’t constrain T to have a particular constructor signature other than an empty constructor, but you can constrain T to have a factory method with the desired signature:
However, I would suggest perhaps using a different creational pattern such as Abstract Factory for this scenario.