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.NodeType == (ExpressionType)MetaExpressionType.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).Try(c => c.Meta); }); }
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; })); }