コード例 #1
0
        private List <Expression> VisitNewExpressionArguments(NewExpression n)
        {
            var arguments = new List <Expression>();

            foreach (var argument in n.Arguments)
            {
                Expression body;
                using (state.CreateScope()) {
                    state.CalculateExpressions = false;
                    body = Visit(argument);
                }
                body = body.IsProjection()
          ? BuildSubqueryResult((ProjectionExpression)body, argument.Type)
          : ProcessProjectionElement(body);
                arguments.Add(body);
            }
            var constructorParameters = n.GetConstructorParameters();

            for (int i = 0; i < arguments.Count; i++)
            {
                if (arguments[i].Type != constructorParameters[i].ParameterType)
                {
                    arguments[i] = Expression.Convert(arguments[i], constructorParameters[i].ParameterType);
                }
            }
            return(arguments);
        }