Exemplo n.º 1
0
            private CodeExpression RewriteAnonymousArray(CodeAnonymousArrayExpression arrayExpression, ref bool didRewrite)
            {
                var  rewrittenElements = new List <CodeExpression>();
                bool elementRewritten  = false;

                foreach (var element in arrayExpression.Elements)
                {
                    rewrittenElements.Add(this.Rewrite(element, ref elementRewritten));
                    didRewrite |= elementRewritten;
                }

                if (didRewrite)
                {
                    return(Code.Array(rewrittenElements.ToArray()));
                }

                return(arrayExpression);
            }
Exemplo n.º 2
0
        /// <summary>
        /// Generates System.CodeDom.CodeExpression from the given expression.
        /// </summary>
        /// <param name="expression">Expression from which System.CodeDom.CodeExpression is generated.</param>
        /// <returns>Generated System.CodeDom.CodeExpression.</returns>
        public virtual CodeExpression Visit(LinqNewArrayExpression expression)
        {
            List <CodeExpression> codeExpressions = new List <CodeExpression>();

            foreach (var childQueryExpression in expression.Expressions)
            {
                codeExpressions.Add(this.GenerateCode(childQueryExpression));
            }

            var collectionType = expression.ExpressionType as QueryCollectionType;

            ExceptionUtilities.CheckObjectNotNull(collectionType, "Expecting expression type to be a collection.");

            var clrQueryType = collectionType.ElementType as IQueryClrType;

            if (clrQueryType != null)
            {
                return(new CodeArrayCreateExpression(Code.TypeRef(clrQueryType.ClrType), codeExpressions.ToArray()));
            }
            else
            {
                return(Code.Array(codeExpressions.ToArray()));
            }
        }