/// <summary> /// Creates an expression tree representing the binding of the value of a property from a /// materialization expression to a parameter of the constructor, factory method, etc. /// </summary> /// <param name="bindingInfo"> The binding information. </param> /// <returns> The expression tree. </returns> public override Expression BindToParameter(ParameterBindingInfo bindingInfo) { var property = ConsumedProperties[0]; return(Expression.Call(bindingInfo.MaterializationContextExpression, MaterializationContext.GetValueBufferMethod) .CreateValueBufferReadValueExpression(property.ClrType, bindingInfo.GetValueBufferIndex(property), property)); }
/// <summary> /// Creates an expression tree representing the binding of the value of a property from a /// materialization expression to a parameter of the constructor, factory method, etc. /// </summary> /// <param name="bindingInfo"> The binding information. </param> /// <returns> The expression tree. </returns> public override Expression BindToParameter(ParameterBindingInfo bindingInfo) { var property = ConsumedProperties[0]; return(Expression.Call( EntityMaterializerSource.TryReadValueMethod.MakeGenericMethod(property.ClrType), Expression.Call(bindingInfo.MaterializationContextExpression, MaterializationContext.GetValueBufferMethod), Expression.Constant(bindingInfo.GetValueBufferIndex(property)), Expression.Constant(property, typeof(IPropertyBase)))); }
/// <summary> /// Creates an expression tree representing the binding of the value of a property from a /// materialization expression to a parameter of the constructor, factory method, etc. /// </summary> /// <param name="bindingInfo"> The binding information. </param> /// <returns> The expression tree. </returns> public override Expression BindToParameter(ParameterBindingInfo bindingInfo) => Expression.NewArrayInit( typeof(object), _bindings.Select( b => { var expression = b.BindToParameter(bindingInfo); if (expression.Type.IsValueType) { expression = Expression.Convert(expression, typeof(object)); } return(expression); }));
/// <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); }
public override Expression BindToParameter(ParameterBindingInfo bindingInfo) => BindToParameter( bindingInfo.MaterializationContextExpression, Expression.Constant(bindingInfo.EntityType));
/// <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)));
public abstract Expression BindToParameter(ParameterBindingInfo bindingInfo);
/// <summary> /// Creates an expression tree that represents creating an entity instance from the given binding /// information. For example, this might be a <see cref="NewExpression" /> to call a constructor, /// or a <see cref="MethodCallExpression" /> to call a factory method. /// </summary> /// <param name="bindingInfo"> Information needed to create the expression. </param> /// <returns> The expression tree. </returns> public abstract Expression CreateConstructorExpression(ParameterBindingInfo bindingInfo);