コード例 #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)
        {
            //ALL, DISTINCT, TOP
            int expressionIndex = expression.SkipMethodChain(0);
            var selectParts = new ICode[expression.Arguments.Count - expressionIndex];
            selectParts[0] = SelectClause;
            for (int i = 0; i < selectParts.Length - 1; i++, expressionIndex++)
            {
                selectParts[i + 1] = converter.ConvertToCode(expression.Arguments[expressionIndex]);
            }

            var select = LineSpace(selectParts);

            //select elemnts.
            var selectTargets = expression.Arguments[expression.Arguments.Count - 1];

            //*
            if (typeof(IAsterisk).IsAssignableFromEx(selectTargets.Type))
            {
                select.Add("*".ToCode());
                return new SelectClauseCode(select);
            }

            //new []{ a, b, c} recursive.
            else if (selectTargets.Type.IsArray)
            {
                var newArrayExp = selectTargets as NewArrayExpression;

                var array = new ICode[newArrayExp.Expressions.Count];
                for (int i = 0; i < array.Length; i++)
                {
                    array[i] = converter.ConvertToCode(newArrayExp.Expressions[i]);
                }

                var coreCode = new VCode(select, new VCode(array) { Indent = 1, Separator = "," });
                return new SelectClauseCode(coreCode);
            }

            //new { item = db.tbl.column }
            else
            {
                var createInfo = ObjectCreateAnalyzer.MakeSelectInfo(selectTargets);
                var elements = new ICode[createInfo.Members.Length];
                for (int i = 0; i < elements.Length; i++)
                {
                    elements[i] = ConvertSelectedElement(converter, createInfo.Members[i]);
                }

                var coreCode = new VCode(select, new VCode(elements) { Indent = 1, Separator = "," });
                return new SelectClauseCode(coreCode);
            }
        }
コード例 #2
0
ファイル: VCode.cs プロジェクト: Codeer-Software/LambdicSql
        /// <summary>
        /// Accept customizer.
        /// </summary>
        /// <param name="customizer">Customizer.</param>
        /// <returns>Destination.</returns>
        public ICode Accept(ICodeCustomizer customizer)
        {
            var dst = customizer.Visit(this);

            if (!ReferenceEquals(this, dst))
            {
                return(dst);
            }

            var hDst = new VCode()
            {
                Indent = Indent, Separator = Separator
            };

            foreach (var e in _core)
            {
                hDst._core.Add(e.Accept(customizer));
            }
            return(hDst);
        }
コード例 #3
0
ファイル: VCode.cs プロジェクト: Codeer-Software/LambdicSql
        /// <summary>
        /// Accept customizer.
        /// </summary>
        /// <param name="customizer">Customizer.</param>
        /// <returns>Destination.</returns>
        public ICode Accept(ICodeCustomizer customizer)
        {
            var dst = customizer.Visit(this);
            if (!ReferenceEquals(this, dst)) return dst;

            var hDst = new VCode() { Indent = Indent, Separator = Separator };
            foreach (var e in _core)
            {
                hDst._core.Add(e.Accept(customizer));
            }
            return hDst;
        }