示例#1
0
        //internal static Expression JustVisit(LambdaExpression expression, PropertyRoute route)
        //{
        //    if (route.Type.IsLite())
        //        route = route.Add("Entity");

        //    return JustVisit(expression, ));
        //}

        internal static Expression JustVisit(LambdaExpression expression, MetaExpression metaExpression)
        {
            var cleaned = MetaEvaluator.Clean(expression);

            var replaced = ExpressionReplacer.Replace(Expression.Invoke(cleaned, metaExpression));

            return(new MetadataVisitor().Visit(replaced));
        }
示例#2
0
        static internal Dictionary <string, Meta> GatherMetadata(Expression expression)
        {
            if (expression == null)
            {
                throw new ArgumentException("expression");
            }

            if (!typeof(IQueryable).IsAssignableFrom(expression.Type))
            {
                throw new InvalidOperationException("Expression type is not IQueryable");
            }

            Expression simplified = MetaEvaluator.Clean(expression);

            MetaProjectorExpression meta = new MetadataVisitor().Visit(simplified) as MetaProjectorExpression;

            if (meta == null)
            {
                return(null);
            }

            var proj = meta.Projector;

            if (proj.NodeType != ExpressionType.New &&                        //anonymous types
                proj.NodeType != ExpressionType.MemberInit &&                 // not-anonymous type
                !(proj is MetaExpression && ((MetaExpression)proj).IsEntity)) // raw-entity!
            {
                return(null);
            }

            PropertyInfo[] props = proj.Type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            return(props.ToDictionary(pi => pi.Name, pi =>
            {
                Expression ex = BindMember(proj, pi, pi.PropertyType);
                return (ex as MetaExpression)?.Meta;
            }));
        }