protected virtual List <Object> VisitNewArrayFromExpressionList(NewArrayExpression na) { List <Object> exprs = VisitExpressionList(na.Expressions); return(exprs); }
/// <summary> /// Visits a NewArrayExpression. /// </summary> /// <param name="node">The NewArrayExpression.</param> /// <returns>The NewArrayExpression.</returns> protected override Expression VisitNewArray(NewArrayExpression node) { throw new NotImplementedException(); }
/// <summary> /// /// </summary> /// <param name="exp"></param> /// <param name="nodeType"></param> /// <param name="firstLevel">是否首次调用,来用修正bool一元运算</param> /// <returns></returns> public CRLExpression.CRLExpression RouteExpressionHandler(Expression exp, ExpressionType?nodeType = null, bool firstLevel = false) { if (exp is BinaryExpression) { BinaryExpression be = (BinaryExpression)exp; return(BinaryExpressionHandler(be.Left, be.Right, be.NodeType)); } else if (exp is MemberExpression) { //区分 属性表达带替换符{0} 变量值不带 #region Member MemberExpression mExp = (MemberExpression)exp; if (mExp.Expression != null && mExp.Expression.NodeType == ExpressionType.Parameter) //like b.Name==b.Name1 或b.Name { var fieldName = mExp.Member.Name; var type = mExp.Expression.Type; CRL.Attribute.FieldAttribute field; var a = TypeCache.GetProperties(type, true).TryGetValue(fieldName, out field); if (!a) { throw new CRLException("类型 " + type.Name + "." + fieldName + " 不是数据库字段,请检查查询条件"); } if (!string.IsNullOrEmpty(field.VirtualField))//按虚拟字段 { //return filed.VirtualField; var queryField = field.VirtualField.Replace("{" + type.FullName + "}", Prefixs[type]);//替换前辍 return(new CRLExpression.CRLExpression() { Type = CRLExpression.CRLExpressionType.Name, Data = queryField }); } var fieldStr = FormatFieldPrefix(type, field.MapingName);//格式化为别名 //return field; if (firstLevel) { //修正bool值一元运算 t1.isTop=1 fieldStr += "=1"; } return(new CRLExpression.CRLExpression() { Type = CRLExpression.CRLExpressionType.Name, Data = fieldStr }); } #endregion var obj = GetParameExpressionValue(mExp); if (obj is Enum) { obj = (int)obj; } else if (obj is Boolean)//sql2000需要转换 { obj = Convert.ToInt32(obj); } //return obj + ""; return(new CRLExpression.CRLExpression() { Type = CRLExpression.CRLExpressionType.Value, Data = obj }); } else if (exp is NewArrayExpression) { #region 数组 NewArrayExpression naExp = (NewArrayExpression)exp; StringBuilder sb = new StringBuilder(); foreach (Expression expression in naExp.Expressions) { sb.AppendFormat(",{0}", RouteExpressionHandler(expression)); } var str = sb.Length == 0 ? "" : sb.Remove(0, 1).ToString(); return(new CRLExpression.CRLExpression() { Type = CRLExpression.CRLExpressionType.Value, Data = str }); #endregion } else if (exp is MethodCallExpression) { MethodCallExpression mcExp = (MethodCallExpression)exp; if (mcExp.Object is MemberExpression) { var mExp = mcExp.Object as MemberExpression; if (mExp.Expression.NodeType != ExpressionType.Parameter) { //not like b.BarCode.Contains("abc") //按变量或常量编译值 var obj = GetParameExpressionValue(exp); //return obj + ""; return(new CRLExpression.CRLExpression() { Type = CRLExpression.CRLExpressionType.Value, Data = obj }); } } else if (mcExp.Object is ConstantExpression) { //var cExp = mcExp.Object as ConstantExpression; //like b.BarCode == aa() var obj = GetParameExpressionValue(exp); //return obj + ""; return(new CRLExpression.CRLExpression() { Type = CRLExpression.CRLExpressionType.Value, Data = obj }); } //var _DBAdapter = DBAdapter.DBAdapterBase.GetDBAdapterBase(dbContext); //var methodAnalyze = new CRL.LambdaQuery.MethodAnalyze(_DBAdapter); #region 方法 //请扩展ExtensionMethod的方法 string methodName = mcExp.Method.Name; parIndex += 1; //var dic = MethodAnalyze.GetMethos(_DBAdapter); //if (!dic.ContainsKey(methodName)) //{ // //return Expression.Lambda(exp).Compile().DynamicInvoke() + ""; // throw new CRLException("LambdaQuery不支持方法" + mcExp.Method.Name); //} string field = ""; #region par List <object> args = new List <object>(); if (mcExp.Object == null) { field = RouteExpressionHandler(mcExp.Arguments[0]).Data.ToString(); } else { field = mcExp.Object.ToString().Split('.')[1]; var mExpression = mcExp.Object as MemberExpression; var type = mExpression.Expression.Type; var filed2 = TypeCache.GetProperties(type, true)[field]; field = FormatFieldPrefix(type, filed2.MapingName); if (mcExp.Arguments.Count > 0) { var obj = GetParameExpressionValue(mcExp.Arguments[0]); args.Add(obj); } } if (mcExp.Arguments.Count > 1) { for (int i = 1; i < mcExp.Arguments.Count; i++) { var obj = GetParameExpressionValue(mcExp.Arguments[i]); args.Add(obj); } } #endregion //int newParIndex = parIndex; if (nodeType == null) { nodeType = ExpressionType.Equal; } //var result = dic[methodName](field, nodeType.Value, ref newParIndex, AddParame, args.ToArray()); //parIndex = newParIndex; //return result; var methodInfo = new CRLExpression.MethodCallObj() { Args = args, ExpressionType = nodeType.Value, MemberName = field.Substring(field.LastIndexOf("}") + 1), MethodName = methodName, MemberQueryName = field }; methodInfo.ReturnType = mcExp.Type; return(new CRLExpression.CRLExpression() { Type = CRLExpression.CRLExpressionType.MethodCall, Data = methodInfo }); #endregion } else if (exp is ConstantExpression) { #region 常量 ConstantExpression cExp = (ConstantExpression)exp; object returnValue; if (cExp.Value == null) { returnValue = "null"; } else { if (cExp.Value is Boolean) { returnValue = Convert.ToInt32(cExp.Value).ToString(); } else if (cExp.Value is Enum) { returnValue = Convert.ToInt32(cExp.Value).ToString(); } else { returnValue = cExp.Value; } } return(new CRLExpression.CRLExpression() { Type = CRLExpression.CRLExpressionType.Value, Data = returnValue }); #endregion } else if (exp is UnaryExpression) { UnaryExpression ue = ((UnaryExpression)exp); if (ue.Operand is MethodCallExpression) { //方法直接下一步解析 return(RouteExpressionHandler(ue.Operand, ue.NodeType)); } else if (ue.Operand is MemberExpression) { MemberExpression mExp = (MemberExpression)ue.Operand; if (mExp.Expression.NodeType != ExpressionType.Parameter) { return(RouteExpressionHandler(ue.Operand)); } var parameter = Expression.Parameter(mExp.Expression.Type, "b"); if (ue.NodeType == ExpressionType.Not) { var ex2 = parameter.Property(mExp.Member.Name).Equal(1); return(RouteExpressionHandler(ex2)); } else if (ue.NodeType == ExpressionType.Convert) { //like Convert(b.Id); var ex2 = parameter.Property(mExp.Member.Name); return(RouteExpressionHandler(ex2)); } } else if (ue.Operand is ConstantExpression) { return(RouteExpressionHandler(ue.Operand)); } throw new CRLException("未处理的一元运算" + ue.NodeType); } else { throw new CRLException("不支持此语法解析:" + exp); } }
internal static NewArrayExpression Update(this NewArrayExpression expr, IEnumerable <Expression> args) { return(Expression.NewArrayInit(expr.Type, args)); }
public static EditableNewArrayExpression ToEditableExpression(this NewArrayExpression ex) { return(new EditableNewArrayExpression(ex)); }
// NewArrayExpression protected internal virtual bool Walk(NewArrayExpression node) { return true; }
protected override Expression VisitNewArray(NewArrayExpression node) { return(base.VisitNewArray(node)); }
private bool CompareNewArray(NewArrayExpression a, NewArrayExpression b) { return(CompareExpressionList(a.Expressions, b.Expressions)); }
static string ExpressionRouter(Expression exp) { string sb = string.Empty; if (exp is BinaryExpression) { BinaryExpression be = ((BinaryExpression)exp); return(BinarExpressionProvider(be.Left, be.Right, be.NodeType)); } else if (exp is MemberExpression) { MemberExpression me = ((MemberExpression)exp); return(me.Member.Name); } else if (exp is NewArrayExpression) { NewArrayExpression ae = ((NewArrayExpression)exp); StringBuilder tmpstr = new StringBuilder(); foreach (Expression ex in ae.Expressions) { tmpstr.Append(ExpressionRouter(ex)); tmpstr.Append(","); } return(tmpstr.ToString(0, tmpstr.Length - 1)); } else if (exp is MethodCallExpression) { MethodCallExpression mce = (MethodCallExpression)exp; if (mce.Method.Name == "Like") { return(string.Format("({0} like {1})", ExpressionRouter(mce.Arguments[0]), ExpressionRouter(mce.Arguments[1]))); } else if (mce.Method.Name == "NotLike") { return(string.Format("({0} Not like {1})", ExpressionRouter(mce.Arguments[0]), ExpressionRouter(mce.Arguments[1]))); } else if (mce.Method.Name == "In") { return(string.Format("{0} In ({1})", ExpressionRouter(mce.Arguments[0]), ExpressionRouter(mce.Arguments[1]))); } else if (mce.Method.Name == "NotIn") { return(string.Format("{0} Not In ({1})", ExpressionRouter(mce.Arguments[0]), ExpressionRouter(mce.Arguments[1]))); } else if (mce.Method.Name == "StartWith") { return(string.Format("{0} like '{1}%'", ExpressionRouter(mce.Arguments[0]), ExpressionRouter(mce.Arguments[1]))); } } else if (exp is ConstantExpression) { ConstantExpression ce = ((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 UnaryExpression) { UnaryExpression ue = ((UnaryExpression)exp); return(ExpressionRouter(ue.Operand)); } return(null); }
private bool CompareNewArray(NewArrayExpression a, NewArrayExpression b) => CompareExpressionList(a.Expressions, b.Expressions);
/// <summary> /// Visits the "new array" expression. /// </summary> /// <param name="na">The "new array" expression.</param> /// <returns>Visit result.</returns> protected abstract TResult VisitNewArray(NewArrayExpression na);
protected override Expression VisitNewArray(NewArrayExpression node) { UpdateHash(node.Type); return(base.VisitNewArray(node)); }
private bool EqualsNewArray(NewArrayExpression x, NewArrayExpression y) { return(x.Type == y.Type && Equals(x.Expressions, y.Expressions, this.Equals)); }
protected virtual Expression VisitNewArray(NewArrayExpression na) { IEnumerable<Expression> exprs = this.VisitExpressionList(na.Expressions); return this.UpdateNewArray(na, na.Type, exprs); }
internal override Expression VisitNewArray(NewArrayExpression na) { throw new NotSupportedException("New Array Expressions not supported."); }
protected override Expression VisitNewArray(NewArrayExpression node) { CheckWhitelistType(node.Type.GetElementType()); return(base.VisitNewArray(node)); }
/// <summary> /// Reads a new array allocation expression from the code. /// </summary> /// <param name="expressionProxy">The proxy object for this expression.</param> /// <param name="parentProxy">The proxy object for the parent.</param> /// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param> /// <param name="type">The type of the array. This may be null for an implicitly typed array.</param> /// <returns>Returns the expression.</returns> private NewArrayExpression GetNewArrayTypeExpression(CodeUnitProxy expressionProxy, CodeUnitProxy parentProxy, bool unsafeCode, Expression type) { Param.AssertNotNull(expressionProxy, "expressionProxy"); Param.AssertNotNull(parentProxy, "parentProxy"); Param.Ignore(unsafeCode); Param.Ignore(type); this.AdvanceToNextCodeSymbol(expressionProxy); // If the type is null, then this is an implicitly typed array and we will only find // array brackets here. Otherwise, we must get the array access expression which includes the type. if (type == null) { this.MovePastArrayBrackets(expressionProxy); } else { Symbol symbol = this.PeekNextSymbol(); // Get all of the array access expressions. while (symbol.SymbolType == SymbolType.OpenSquareBracket) { type = this.GetArrayAccessExpression(expressionProxy, type, ExpressionPrecedence.None, unsafeCode); if (type == null || type.Children.Count == 0) { throw this.CreateSyntaxException(); } symbol = this.PeekNextSymbol(); } } // Make sure there was at least one array access. if (type != null && type.ExpressionType != ExpressionType.ArrayAccess) { throw this.CreateSyntaxException(); } // Get the next symbol and check the type. Symbol nextSymbol = this.PeekNextSymbol(); // Get the initializer if there is one. ArrayInitializerExpression initializer = null; if (nextSymbol.SymbolType == SymbolType.OpenCurlyBracket) { initializer = this.GetArrayInitializerExpression(expressionProxy, unsafeCode); } // For an implicitly typed array, an array initializer is required. if (type == null && initializer == null) { throw this.CreateSyntaxException(); } // Create and return the expression. var expression = new NewArrayExpression(expressionProxy, type as ArrayAccessExpression, initializer); parentProxy.Children.Add(expression); return expression; }
public virtual TranResult CreateUpdateTSQL <TEntity>(TEntity entity, LambdaExpression where = null, LambdaExpression select = null) { this.Reset(); Type type = typeof(TEntity); TranResult tr = new TranResult(); tr.TableMapping = type.GetTableMapping(); this.AddTable(tr.TableMapping); this.Append("UPDATE "); this.Append(tr.TableMapping.Name); this.Append(" SET "); Dictionary <string, object> dic = new Dictionary <string, object>(); if (select != null) { NewExpression ue = select.Body as NewExpression; NewArrayExpression ne = ue.Arguments[0] as NewArrayExpression; foreach (var item in ne.Expressions) { string name = string.Empty; if (item.NodeType == ExpressionType.MemberAccess) { MemberExpression me = item as MemberExpression; name = me.Member.Name; } else if (item.NodeType == ExpressionType.Convert) { UnaryExpression iue = item as UnaryExpression; MemberExpression me = iue.Operand as MemberExpression; name = me.Member.Name; } if (string.IsNullOrEmpty(name)) { continue; } PropertyInfo pi = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); if (pi == null || pi.IsIgnore() || (pi.Name == tr.TableMapping.PrimaryKey.Name && tr.TableMapping.PrimaryKey.IsIdentity) || (!pi.PropertyType.IsValueType && pi.PropertyType != typeof(string))) { continue; } if (pi.PropertyType.IsEnum) { dic.Add(pi.Name, (int)Enum.Parse(pi.PropertyType, pi.GetValue(entity, null).ToString())); } else { dic.Add(pi.Name, pi.GetValue(entity, null)); } } } else { //不获取继承属性 为实例属性 为公开的 PropertyInfo[] pis = type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public); foreach (var item in pis) { if (item.IsIgnore() || (item.Name == tr.TableMapping.PrimaryKey.Name && tr.TableMapping.PrimaryKey.IsIdentity) || (!item.PropertyType.IsValueType && item.PropertyType != typeof(string))) { continue; } if (item.PropertyType.IsEnum) { dic.Add(item.Name, (int)Enum.Parse(item.PropertyType, item.GetValue(entity, null).ToString())); } else { dic.Add(item.Name, item.GetValue(entity, null)); } } } int index = 0; int count = dic.Count; foreach (var item in dic) { this.Append(item.Key); this.Append(" = "); this.CreateParameter(item.Value); if (index++ != count - 1) { this.Append(","); } } this.VisitWhereExpression(where); return(this.GetModifyTranResult(tr)); }
protected NewArrayExpression UpdateNewArray(NewArrayExpression na, Type arrayType, IEnumerable<Expression> expressions) { if (expressions != na.Expressions || na.Type != arrayType) { if (na.NodeType == ExpressionType.NewArrayInit) { return Expression.NewArrayInit(arrayType.GetElementType(), expressions); } else { return Expression.NewArrayBounds(arrayType.GetElementType(), expressions); } } return na; }
private static string VisitSubExpression(NewArrayExpression expression, ParameterExpression firstParameter) { throw new NotImplementedException(); }
/// <summary> /// Visits the new array. /// </summary> /// <param name="na">The na.</param> /// <returns></returns> protected virtual Expression VisitNewArray(NewArrayExpression na) { IEnumerable <Expression> exprs = this.VisitExpressionList(na.Expressions); return(this.UpdateNewArray(na, na.Type, exprs)); }
protected override Expression VisitNewArray(NewArrayExpression node) { return(GiveUp(node)); }
protected virtual Expression VisitNewArray(NewArrayExpression expr) { return(expr.Update(expr.Expressions.Select(a => Visit(a)))); }
internal override Expression VisitNewArray(NewArrayExpression na) { throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Initializing instances of the entity type {0} with the expression {1} is not supported.", type, na.ToString())); }
protected override Expression VisitNewArray(NewArrayExpression node) => VisitChildren(node, other => Visit(node.Expressions, node.Expressions));
/// <summary> /// Visits the children of <see cref="System.Linq.Expressions.NewArrayExpression"/>. /// </summary> /// <param name="node">The expression to visit.</param> /// <returns>The modified expression, if it or any subexpression was modified; otherwise, /// returns the original expression.</returns> protected override Expression VisitNewArray(NewArrayExpression node) { throw new NotSupportedException(string.Format(Resources.EX_PROCESS_NODE_NOT_SUPPORT, node.GetType().Name)); }
public virtual void VisitNewArrayExpression(NewArrayExpression expression) { VisitAbstractExpression(expression); }
protected virtual bool CompareNewArray(NewArrayExpression a, NewArrayExpression b) { return(CompareExpressionList(a.Expressions, b.Expressions)); }
/// <summary> /// Visit a <see cref="NewArrayExpression"/>. /// </summary> /// <param name="expression"><see cref="NewArrayExpression"/> to visit.</param> /// <returns>Returns the result of the visit.</returns> protected abstract object VisitNewArrayExpression(NewArrayExpression expression);
private void FindColumns(Expression expression, IList <TableColumn> columnList) { if (expression is ParameterExpression) { ParameterExpression e = expression as ParameterExpression; string selector = e.Name; for (int i = 0; i < this.tables.Count; i++) { if (this.selectors[i] == selector) { AddAllColumns(this.tables[i], columnList); break; } } } else if (expression.NodeType == ExpressionType.MemberAccess) { this.FindColumns(expression as MemberExpression, columnList); } else if (expression is MethodCallExpression) { this.FindColumns(expression as MethodCallExpression, columnList); } else if (expression is BinaryExpression) { BinaryExpression e = expression as BinaryExpression; this.FindColumns(e.Left, columnList); this.FindColumns(e.Right, columnList); } else if (expression is UnaryExpression) { UnaryExpression e = expression as UnaryExpression; this.FindColumns(e.Operand, columnList); } else if (expression is ConditionalExpression) { ConditionalExpression e = expression as ConditionalExpression; this.FindColumns(e.Test, columnList); this.FindColumns(e.IfTrue, columnList); this.FindColumns(e.IfFalse, columnList); } else if (expression is InvocationExpression) { InvocationExpression e = expression as InvocationExpression; this.FindColumns(e.Expression, columnList); this.FindColumns(e.Arguments, columnList); } else if (expression is LambdaExpression) { LambdaExpression e = expression as LambdaExpression; this.FindColumns(e.Body, columnList); } else if (expression is ListInitExpression) { ListInitExpression e = expression as ListInitExpression; this.FindColumns(e.NewExpression, columnList); foreach (ElementInit ei in e.Initializers) { this.FindColumns(ei.Arguments, columnList); } } else if (expression is MemberInitExpression) { MemberInitExpression e = expression as MemberInitExpression; this.FindColumns(e.NewExpression, columnList); foreach (MemberAssignment b in e.Bindings) { this.FindColumns(b.Expression, columnList); } } else if (expression is NewExpression) { NewExpression e = expression as NewExpression; this.FindColumns(e.Arguments, columnList); } else if (expression is NewArrayExpression) { NewArrayExpression e = expression as NewArrayExpression; this.FindColumns(e.Expressions, columnList); } else if (expression is TypeBinaryExpression) { TypeBinaryExpression e = expression as TypeBinaryExpression; this.FindColumns(e.Expression, columnList); } }
public ObservableArrayInitializationExpression(NewArrayExpression node, ObservableExpressionBinder binder) : this(node.Expressions.Select(e => binder.VisitObservable <T>(e))) { }
protected override Expression VisitNewArray(NewArrayExpression node) => null;
protected virtual bool CompareNewArray(NewArrayExpression a, NewArrayExpression b) { return this.CompareExpressionList(a.Expressions, b.Expressions); }
/// <summary> /// Traverses the new array expression. /// </summary> /// <param name="newArrayExpression">The new array expression.</param> private void TraverseNewArrayExpression(NewArrayExpression newArrayExpression) { TraverseExpressions(newArrayExpression.Expressions); }
public NewArrayExpressionProxy(NewArrayExpression node) { _node = node; }
internal override Expression VisitNewArray(NewArrayExpression na) { throw new NotSupportedException(SR.ALinqNewArrayNotSupported); }
protected internal virtual void PostWalk(NewArrayExpression node) { }
protected override Expression VisitNewArray(NewArrayExpression na) { return base.VisitNewArray(na); }