Ejemplo n.º 1
0
        /// <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));
        }
Ejemplo n.º 2
0
        /// <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))));
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 5
0
 public override Expression BindToParameter(ParameterBindingInfo bindingInfo)
 => BindToParameter(
     bindingInfo.MaterializationContextExpression,
     Expression.Constant(bindingInfo.EntityType));
Ejemplo n.º 6
0
 /// <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)));
Ejemplo n.º 7
0
 public abstract Expression BindToParameter(ParameterBindingInfo bindingInfo);
Ejemplo n.º 8
0
 /// <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);