public void VisitProjection(QNode node) { var left = ContextExpression.Pop(); Type projectorType = null; var dynamicProperties = new List <DynamicProperty>(); var bindings1 = MemberNodeConverter.ConvertToBindings(ContextParameters.Peek(), node); foreach (var binding in bindings1) { var property = new DynamicProperty(binding.Key, binding.Value.Type); dynamicProperties.Add(property); } projectorType = ClassFactory.Instance.GetDynamicClass(dynamicProperties); var resultProperties = projectorType.GetProperties(); var bindingsSource = new List <Expression>(); var bindingsProperties = new List <PropertyInfo>(); foreach (var binding in bindings1) { bindingsProperties.Add(resultProperties.FirstOrDefault(x => x.Name == binding.Key)); bindingsSource.Add(binding.Value); } var bindings = new List <MemberBinding>(); for (var i = 0; i < bindingsSource.Count; i++) { var exp = Expression.Bind(bindingsProperties[i], bindingsSource[i]); bindings.Add(exp); } var lambda = Expression.Lambda( Expression.MemberInit(Expression.New(projectorType.GetConstructor(Type.EmptyTypes)), bindings), ContextParameters.Peek()); var result = BuildMethodCallExpression(MethodType.Select, left, lambda); ContextExpression.Push(result); HasProjection = true; Mapper.EnableMapping = false; }
public void VisitMethod(QNode node) { MethodType method; if (node.Value is long) { method = (MethodType)Convert.ToInt16(node.Value); } else { Enum.TryParse(Convert.ToString(node.Value), out method); } var right = ContextExpression.Pop(); var left = ContextExpression.Pop(); var lambda = Expression.Lambda(right, ContextParameters.Peek()); var exp = BuildMethodCallExpression(method, left, lambda); ContextExpression.Push(exp); }
public void VisitMember(QNode node) { var member = MemberNodeConverter.ConvertToMemberExpression(ContextParameters.Peek(), node); ContextExpression.Push(member); }