Beispiel #1
0
        static void NewArrayInit()
        {
            // <Snippet1>
            List <System.Linq.Expressions.Expression> trees =
                new List <System.Linq.Expressions.Expression>()
            {
                System.Linq.Expressions.Expression.Constant("oak"),
                System.Linq.Expressions.Expression.Constant("fir"),
                System.Linq.Expressions.Expression.Constant("spruce"),
                System.Linq.Expressions.Expression.Constant("alder")
            };

            // Create an expression tree that represents creating and
            // initializing a one-dimensional array of type string.
            System.Linq.Expressions.NewArrayExpression newArrayExpression =
                System.Linq.Expressions.Expression.NewArrayInit(typeof(string), trees);

            // Output the string representation of the Expression.
            Console.WriteLine(newArrayExpression.ToString());

            // This code produces the following output:
            //
            // new [] {"oak", "fir", "spruce", "alder"}
            // </Snippet1>
        }
Beispiel #2
0
 protected override System.Linq.Expressions.Expression VisitNewArray(System.Linq.Expressions.NewArrayExpression na)
 {
     foreach (System.Linq.Expressions.Expression current in na.Expressions)
     {
         _strSql.Append(",");
         this.Visit(current);
     }
     return(na);
 }
        /// <summary>
        /// 表达式路由
        /// </summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        string ExpressionRouter(System.Linq.Expressions.Expression exp)
        {
            //获取实体列的特性
            List <EntityPropColumnAttributes> columnAttrList = AttributeHelper.GetEntityColumnAtrributes <TEntity>();

            string sb = string.Empty;

            if (exp is System.Linq.Expressions.BinaryExpression)//二元运算符
            {
                System.Linq.Expressions.BinaryExpression be = ((System.Linq.Expressions.BinaryExpression)exp);
                return(BinarExpressionProvider(be.Left, be.Right, be.NodeType));
            }
            else if (exp is System.Linq.Expressions.MemberExpression)//成员
            {
                System.Linq.Expressions.MemberExpression me = ((System.Linq.Expressions.MemberExpression)exp);
                return(me.Member.Name);
            }
            else if (exp is System.Linq.Expressions.NewArrayExpression)//数组
            {
                System.Linq.Expressions.NewArrayExpression ae = ((System.Linq.Expressions.NewArrayExpression)exp);
                StringBuilder tmpstr = new StringBuilder();
                foreach (System.Linq.Expressions.Expression ex in ae.Expressions)
                {
                    tmpstr.Append(ExpressionRouter(ex));
                    tmpstr.Append(",");
                }
                return(tmpstr.ToString(0, tmpstr.Length - 1));
            }
            else if (exp is System.Linq.Expressions.MethodCallExpression)//方法
            {
                return(MethodExpression(exp));
            }
            else if (exp is System.Linq.Expressions.ConstantExpression)
            {
                System.Linq.Expressions.ConstantExpression ce = ((System.Linq.Expressions.ConstantExpression)exp);
                if (ce.Value == null)
                {
                    return("null");
                }
                else if (ce.Value is ValueType)
                {
                    return(ce.Value.ToString());
                }
                else if (ce.Value is string || ce.Value is DateTime || ce.Value is char)
                {
                    return(string.Format("{0}", ce.Value.ToString()));
                }
            }
            else if (exp is System.Linq.Expressions.UnaryExpression)
            {
                System.Linq.Expressions.UnaryExpression ue = ((System.Linq.Expressions.UnaryExpression)exp);
                return(ExpressionRouter(ue.Operand));
            }
            return(null);
        }
Beispiel #4
0
        static void NewArrayBounds()
        {
            // <Snippet2>
            // Create an expression tree that represents creating a
            // two-dimensional array of type string with bounds [3,2].
            System.Linq.Expressions.NewArrayExpression newArrayExpression =
                System.Linq.Expressions.Expression.NewArrayBounds(
                    typeof(string),
                    System.Linq.Expressions.Expression.Constant(3),
                    System.Linq.Expressions.Expression.Constant(2));

            // Output the string representation of the Expression.
            Console.WriteLine(newArrayExpression.ToString());

            // This code produces the following output:
            //
            // new System.String[,](3, 2)
            // </Snippet2>
        }
Beispiel #5
0
 protected override System.Linq.Expressions.Expression VisitNewArray(System.Linq.Expressions.NewArrayExpression na)
 {
     foreach (System.Linq.Expressions.Expression current in na.Expressions)
     {
         _strSql.Append(",");
         _ParamSql.Append(",");
         this._foundSpecialMethod = false;
         this._foundAs            = false;
         this.Visit(current);
         if (this._foundAs == false && this._CurrentMemberInfo != null && this.ExcuteType == DMSExcuteType.SELECT)
         {
             string text = GetMemberInfoName(this._CurrentMemberInfo.Name);
             if (this.SplitExpression.TableMapping.TokenFlag == true)
             {
                 text = this.Provider.BuildColumnName(text);
             }
             _ParamSql.Append(text);
         }
     }
     return(na);
 }