public class Jit { T _instance; object[] _ctor_params; public Jit(object[] ctor_params) { _ctor_params = ctor_params; } public Jit() { } public T create(object[] ctor_params) { Type[] param_types = ctor_params.Aggregate>( new List(), (List lt, object o) => { lt.Add(o.GetType()); return lt; }).ToArray(); var ctor = typeof(T).GetConstructor(param_types); if (ctor == null) throw new Exception(param_types.Aggregate( "No constructor found for " + typeof(T).Name + " taking", (string i, Type t) => { return i + " " + t.Name; })); return (T)ctor.Invoke(_ctor_params); } public T create() { return (_ctor_params == null) ? create(new object[] { }) : create(_ctor_params); } public T single() { if (_instance == null) _instance = create(); return _instance; } }