/// <summary> /// Creates a <see cref="MethodCallExpression" /> using the given method. /// </summary> /// <param name="bindingInfo"> Information needed to create the expression. </param> /// <returns> The expression tree. </returns> public override Expression CreateConstructorExpression(ParameterBindingInfo bindingInfo) { var arguments = ParameterBindings.Select(b => b.BindToParameter(bindingInfo)); Expression expression = _factoryInstance == null ? Expression.Call( _factoryMethod, arguments) : Expression.Call( Expression.Constant(_factoryInstance), _factoryMethod, arguments); if (_factoryMethod.ReturnType != RuntimeType) { expression = Expression.Convert(expression, RuntimeType); } return(expression); }
/// <summary> /// Creates a <see cref="NewExpression" /> that represents creating an entity instance using the given /// constructor. /// </summary> /// <param name="bindingInfo"> Information needed to create the expression. </param> /// <returns> The expression tree. </returns> public override Expression CreateConstructorExpression(ParameterBindingInfo bindingInfo) => Expression.New( Constructor, ParameterBindings.Select(b => b.BindToParameter(bindingInfo)));