Example #1
0
        public void Parse()
        {
            Pieces.Clear();

            var pathPieces = Path.Split('.').ToList();
            var param      = Parameter;
            ExpressionParserPiece parent = null;

            pathPieces.ForEach(pp =>
            {
                var memberExpression = Expression.PropertyOrField(param, pp);
                var current          = new ExpressionParserPiece
                {
                    Type = memberExpression.Type,
                    IsGenericEnumerable = QueryableHelpers.IsGenericEnumerable(memberExpression),
                    EnumerableType      = memberExpression.Type.GenericTypeArguments.FirstOrDefault(),
                    Parent = parent,
                    Name   = pp
                };

                Pieces.Add(current);

                // for next iteration.
                param  = Expression.Parameter(current.IsGenericEnumerable ? current.EnumerableType : current.Type);
                parent = current;
            });
        }
Example #2
0
        public static ExpressionParserPiece GetFirstEnumerableParent(ExpressionParserPiece piece)
        {
            if (piece.Parent == null)
            {
                return(null);
            }

            if (piece.Parent.IsGenericEnumerable)
            {
                return(piece.Parent);
            }

            return(GetFirstEnumerableParent(piece.Parent));
        }
Example #3
0
        public static ExpressionParserPiece FirstEnumerableParent(this ExpressionParserPiece piece)
        {
            var result = ExpressionParser.GetFirstEnumerableParent(piece);

            return(result);
        }