示例#1
0
 public QDescriptorConverter(MapperConfiguration conf, Expression query)
 {
     ContextExpression   = new Stack <Expression>();
     ContextParameters   = new Stack <ParameterExpression>();
     Mapper              = new Mapping(conf);
     MemberNodeConverter = new MemberNodeConverter(Mapper);
     Query = query;
 }
示例#2
0
        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;
        }
示例#3
0
        public void VisitMember(QNode node)
        {
            var member = MemberNodeConverter.ConvertToMemberExpression(ContextParameters.Peek(), node);

            ContextExpression.Push(member);
        }