Exemplo n.º 1
0
        /// <summary>
        /// Convert expression to code.
        /// </summary>
        /// <param name="expression">Expression.</param>
        /// <param name="converter">Expression converter.</param>
        /// <returns>Parts.</returns>
        public override ICode Convert(MethodCallExpression expression, ExpressionConverter converter)
        {
            var name     = FromConverterAttribute.GetSubQuery(expression.Arguments[0]);
            var coreType = expression.Arguments[0].Type.GetGenericArgumentsEx()[0];
            var info     = ObjectCreateAnalyzer.MakeObjectCreateInfo(coreType);

            //TODO
            return(new WithEntriedCode(Line(name.ToCode(), Blanket(info.Members.Select(e => e.Name.ToCode()).ToArray())), new[] { name }));
        }
        /// <summary>
        /// Convert expression to code.
        /// </summary>
        /// <param name="expression">Expression.</param>
        /// <param name="converter">Expression converter.</param>
        /// <returns>Parts.</returns>
        public override ICode Convert(MethodCallExpression expression, ExpressionConverter converter)
        {
            //TODO SkipMethodChain -> other
            var startIndex = expression.SkipMethodChain(0);
            var tabkeIndex = HasTop ? startIndex + 1 : startIndex;

            //top
            var codes = new List <ICode>();

            if (HasTop)
            {
                var top = converter.ConvertToCode(expression.Arguments[startIndex]);
                codes.Add(top);
            }

            //table
            var table = converter.ConvertToCode(expression.Arguments[tabkeIndex]);

            codes.Add(table);

            //hints
            if (HasHints)
            {
                var newArray = expression.Arguments[startIndex + 1] as NewArrayExpression;
                var hints    = new ICode[newArray.Expressions.Count];
                int i        = 0;
                foreach (var e in newArray.Expressions)
                {
                    hints[i++] = converter.ConvertToCode(e);
                }
                codes.Add(Func("WITH".ToCode(), hints));
            }

            var sub = FromConverterAttribute.GetSubQuery(expression.Arguments[tabkeIndex]);

            if (sub != null)
            {
                codes.Add(sub.ToCode());
            }

            return(new VCode(codes)
            {
                Separator = " "
            });
        }