/// <summary> /// Creates a factory for an empty constructor. /// </summary> /// <typeparam name="T">The type of instance</typeparam> /// <param name="type">The type of instance</param> /// <param name="constructor">The constructor info</param> /// <returns>The factory</returns> public Func <T> CreateConstructor <T>(Type type, ConstructorInfo constructor) { try { Expression newExpression = Expression.New(type); newExpression = ExpressionUtils.EnsureCastExpression(newExpression, typeof(T)); LambdaExpression lambdaExpression = Expression.Lambda(typeof(Func <T>), newExpression); return((Func <T>)lambdaExpression.Compile()); } catch { return(() => (T)Activator.CreateInstance(type)); } }