/// <summary> /// The visit new. /// </summary> /// <param name="exp"> /// The exp. /// </param> /// <returns> /// The <see cref="Expression" />. /// </returns> protected override Expression VisitNew(NewExpression exp) { // Typisierte Select if (exp.Members == null) { return(exp); } // anonymes Type QNode bindingNode = null; for (int i = 0; i < exp.Members.Count; i++) { var bindingProperty = exp.Members[i].Name; var builder = new MemberNodeBuilder(); builder.Visit(exp.Arguments[i]); var node = new QNode() { Type = NodeType.Member, Value = bindingProperty + ":" + builder.GetPath() }; if (bindingNode == null) { bindingNode = node; } else { bindingNode.Left = node; } } this.Context.Push(bindingNode); return(exp); }
/// <summary> /// The visit member access. /// </summary> /// <param name="memberAccess"> /// The memberAccess. /// </param> /// <returns> /// The <see cref="Expression" />. /// </returns> protected virtual Expression VisitMemberAccess(MemberExpression memberAccess) { if (memberAccess.Expression.Type.IsGenericType && typeof(IConstantPlaceHolder).IsAssignableFrom(memberAccess.Expression.Type)) { var func = Expression.Lambda(memberAccess.Expression).Compile(); var ph = (IConstantPlaceHolder)func.DynamicInvoke(); var value = ph.GetValue(); var node = new QNode() { Type = NodeType.Constant, Value = value }; this.Context.Push(node); return(memberAccess); } if (memberAccess.Expression.NodeType == ExpressionType.Constant) { var value = this.ResolveValue(memberAccess); var node = new QNode() { Type = NodeType.Constant, Value = value }; this.Context.Push(node); } else { var builder = new MemberNodeBuilder(); builder.Visit(memberAccess); var node = new QNode() { Type = NodeType.Member, Value = builder.GetPath() }; this.Context.Push(node); } return(memberAccess); }
/// <summary> /// The visit member init. /// </summary> /// <param name="exp"> /// The exp. /// </param> /// <returns> /// The <see cref="Expression" />. /// </returns> protected override Expression VisitMemberInit(MemberInitExpression exp) { QNode bindingNode = null; for (int i = 0; i < exp.Bindings.Count; i++) { var builder = new MemberNodeBuilder(); builder.Visit(((MemberAssignment)exp.Bindings[i]).Expression); var node = new QNode() { Type = NodeType.Member, Value = exp.Bindings[i].Member.Name + ":" + builder.GetPath() }; if (bindingNode == null) { bindingNode = node; } else { bindingNode.Left = node; } } this.Context.Push(bindingNode); return(exp); }