Inheritance: System.Linq.Expressions.Expression
 protected MemberExpression UpdateMemberAccess(MemberExpression m, Expression expression, MemberInfo member)
 {
     if (expression != m.Expression || member != m.Member) {
         return Expression.MakeMemberAccess(expression, member);
     }
     return m;
 }
 Expression VisitFieldSelection(MemberExpression m)
 {
     var fieldName = Mapping.GetFieldName(SourceType, m);
     fieldNames.Add(fieldName);
     var getFieldExpression = Expression.Call(null, GetDictionaryValueMethod, Expression.PropertyOrField(BindingParameter, "fields"), Expression.Constant(fieldName), Expression.Constant(m.Type));
     return Expression.Convert(getFieldExpression, m.Type);
 }
        public static PropertyInfo GetPropertyInfo <TSource, TProperty>(this Expression <Func <TSource, TProperty> > propertyLambda)
        {
            Type type = typeof(TSource);

            System.Linq.Expressions.MemberExpression member = propertyLambda.Body as MemberExpression;
            if (member == null)
            {
                throw new ArgumentException(string.Format(
                                                "Expression '{0}' refers to a method, not a property.",
                                                propertyLambda.ToString()));
            }

            PropertyInfo propInfo = member.Member as PropertyInfo;

            if (propInfo == null)
            {
                throw new ArgumentException(string.Format(
                                                "Expression '{0}' refers to a field, not a property.",
                                                propertyLambda.ToString()));
            }

            if (type != propInfo.ReflectedType &&
                !type.IsSubclassOf(propInfo.ReflectedType))
            {
                throw new ArgumentException(string.Format(
                                                "Expression '{0}' refers to a property that is not from type {1}.",
                                                propertyLambda.ToString(),
                                                type));
            }

            return(propInfo);
        }
        public IncludeQueryAnnotation([NotNull] MemberExpression navigationPropertyPath)
        {
            Check.NotNull(navigationPropertyPath, nameof(navigationPropertyPath));

            NavigationPropertyPath = navigationPropertyPath;
            _chainedNavigationProperties = new List<PropertyInfo>();
        }
        protected override Expression VisitMemberAccess(MemberExpression m)
        {
            Expression source = this.Visit(m.Expression);
            EntityExpression ex = source as EntityExpression;
            IMemberMapping mm = null;

            if (ex != null && (mm = ex.Entity.Get(m.Member)) != null && mm.IsRelationship)
            {
                ProjectionExpression projection = (ProjectionExpression)this.Visit(this.expressionBuilder.GetMemberExpression(source, ex.Entity, m.Member));
                if (this.currentFrom != null && mm.IsManyToOne)
                {
                    // convert singleton associations directly to OUTER APPLY
                    projection = this.expressionBuilder.AddOuterJoinTest(projection);
                    Expression newFrom = new JoinExpression(JoinType.OuterApply, this.currentFrom, projection.Select, null);
                    this.currentFrom = newFrom;
                    return projection.Projector;
                }
                return projection;
            }
            else
            {
                Expression result = QueryBinder.BindMember(source, m.Member);
                MemberExpression mex = result as MemberExpression;
                if (mex != null && mex.Member == m.Member && mex.Expression == m.Expression)
                {
                    return m;
                }
                return result;
            }
        }
		protected override Expression VisitMemberExpression(MemberExpression expression)
		{
			if (!IsMemberOfModel(expression))
			{
				return base.VisitMemberExpression(expression);
			}

			if (expression.IsGroupingKeyOf(_groupBy))
			{
				return _groupBy.KeySelector;
			}

			var elementSelector = _groupBy.ElementSelector;

			if ((elementSelector is MemberExpression) || (elementSelector is QuerySourceReferenceExpression))
			{
				// If ElementSelector is MemberExpression, just return
				return base.VisitMemberExpression(expression);
			}

			if ((elementSelector is NewExpression || elementSelector.NodeType == ExpressionType.Convert)
				&& elementSelector.Type == expression.Expression.Type)
			{
				//TODO: probably we should check this with a visitor
				return Expression.MakeMemberAccess(elementSelector, expression.Member);
			}

			throw new NotImplementedException();
		}
 protected override Expression VisitMember(MemberExpression node)
 {
     var visitor = new MemberExpressionVisitor(this.Context);
     visitor.Visit(node);
     Column = visitor.Column;
     return node;
 }
 protected override Expression VisitMemberAccess(MemberExpression m)
 {
     if (m.Member.DeclaringType.Namespace.ToLower().CompareTo("artefacts.service") == 0)	//.Equals(typeof(Repository)))// && m.Expression == null)
     {
         object value = null;
         object container = null;
         if (m.Expression != null)
         {
             Expression mExp = this.Visit(m.Expression);
             if (!(mExp is ConstantExpression))
                 throw new ApplicationException("m.Expression should be null or a ConstantExpression (after processing with ServerQueryVisitor)");
             container = ((ConstantExpression)mExp).Value;
         }
         switch (m.Member.MemberType)
         {
             case MemberTypes.Field:
                 value = ((FieldInfo)m.Member).GetValue(container);
                 break;
             case MemberTypes.Property:
                 value = ((PropertyInfo)m.Member).GetValue(container, null);		// TODO: Need to handle indexer properties? IndexExpression does not derive from MemberExpression
                 break;
             default:
                 throw new ApplicationException(string.Format("Unknown MemberType in MemberExpression: \"{0}\"", m.Member.MemberType.ToString()));
         }
         return Expression.Constant(value);
     }
     return base.VisitMemberAccess(m);
 }
 private void CreatePropertyExpressions()
 {
     var name = Expression.Constant(_property.Name, typeof(string));
     _containsKey = Expression.Call(_param, DictionaryContainsKeyMethod, name);
     _nameProperty = Expression.Property(_obj, _property);
     _itemProperty = Expression.Property(_param, DictionaryIndexerProperty, name);
 }
        protected override Expression VisitMemberAccess(MemberExpression m)
        {
            var declaringType = m.Member.DeclaringType;
            if (declaringType == typeof (string)) {
                switch (m.Member.Name) {
                    case "Length": {
                        Write("LENGTH(");
                        Visit(m.Expression);
                        Write(")");
                        return m;
                    }
                }
            } else if (declaringType == typeof (DateTime) ||
                       declaringType == typeof (DateTimeOffset)) {
                switch (m.Member.Name) {
                    case "Day": {
                        Write("DAY(");
                        Visit(m.Expression);
                        Write(")");
                        return m;
                    }
                    case "Year": {
                        Write("YEAR(");
                        Visit(m.Expression);
                        Write(")");
                        return m;
                    }
                    // TODO: Continue with date function
                }
            } else if (declaringType == typeof (TimeSpan)) {

            }

            return base.VisitMemberAccess(m);
        }
        /// <summary>
        /// Visits the member.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        protected override Expression VisitMember(MemberExpression node)
        {
            CompiledExpression expression;

            // Ensure that all property mappings are registered (the usual way -> on object type)
            EnsureTypeInitialized(node.Member.DeclaringType);

            // Ensure that all property mappings are registered (when the linq query was built towards an interface)
            if (IsBuildOnInterface(node))
            {
                EnsureTypeInitialized(node.Expression.Type);
            }

            if ((IsBuildOnInterface(node) && this.map.TryGetValue(node.Member, node.Expression.Type, out expression))
                 || this.map.TryGetValue(node.Member, out expression))
            {
                return this.VisitCompiledExpression(expression, node.Expression);
            }

            if (typeof(CompiledExpression).IsAssignableFrom(node.Member.DeclaringType))
            {
                return this.VisitCompiledExpression(expression, node.Expression);
            }

            return base.VisitMember(node);
        }
 protected override Expression VisitMemberAccess(MemberExpression m) {
     if (m.Member.DeclaringType == typeof(string)) {
         switch (m.Member.Name) {
             case "Length":
                 sb.Append("CHAR_LENGTH(");
                 this.Visit(m.Expression);
                 sb.Append(")");
                 return m;
         }
     } else if (m.Member.DeclaringType == typeof(DateTime) || m.Member.DeclaringType == typeof(DateTimeOffset)) {
         switch (m.Member.Name) {
             case "Day":
                 sb.Append("DAY(");
                 this.Visit(m.Expression);
                 sb.Append(")");
                 return m;
             case "Month":
                 sb.Append("MONTH(");
                 this.Visit(m.Expression);
                 sb.Append(")");
                 return m;
             case "Year":
                 sb.Append("YEAR(");
                 this.Visit(m.Expression);
                 sb.Append(")");
                 return m;
             case "Hour":
                 sb.Append("HOUR( ");
                 this.Visit(m.Expression);
                 sb.Append(")");
                 return m;
             case "Minute":
                 sb.Append("MINUTE( ");
                 this.Visit(m.Expression);
                 sb.Append(")");
                 return m;
             case "Second":
                 sb.Append("SECOND( ");
                 this.Visit(m.Expression);
                 sb.Append(")");
                 return m;
             case "Millisecond":
                 sb.Append("MICROSECOND( ");
                 this.Visit(m.Expression);
                 sb.Append(")");
                 return m;
             case "DayOfWeek":
                 sb.Append("(DAYOFWEEK(");
                 this.Visit(m.Expression);
                 sb.Append(") - 1)");
                 return m;
             case "DayOfYear":
                 sb.Append("(DAYOFYEAR( ");
                 this.Visit(m.Expression);
                 sb.Append(") - 1)");
                 return m;
         }
     }
     throw new NotSupportedException(string.Format("The member '{0}' is not supported", m.Member.Name));
 }
		protected override Expression VisitMember(MemberExpression expression)
		{
			if (_stack == null) return base.VisitMember(expression);
			var name = this.Resolve(expression.Member);
			_stack.Push(name);
			return base.VisitMember(expression);
		}
Exemple #14
0
        /// <summary>
        ///     Replaces a <see cref="DbQuery" /> or <see cref="DbQuery{T}" /> property with a constant expression
        ///     for the underlying <see cref="ObjectQuery" />.
        /// </summary>
        /// <param name="node"> The node to replace. </param>
        /// <returns> A new node, which may have had the replacement made. </returns>
        protected override Expression VisitMember(MemberExpression node)
        {
            Check.NotNull(node, "node");

            var propInfo = node.Member as PropertyInfo;
            var memberExpression = node.Expression as MemberExpression;

            if (propInfo != null
                && memberExpression != null
                &&
                typeof(IQueryable).IsAssignableFrom(propInfo.PropertyType)
                &&
                typeof(DbContext).IsAssignableFrom(node.Member.DeclaringType))
            {
                var context = GetContextFromConstantExpression(memberExpression.Expression, memberExpression.Member);
                if (context != null)
                {
                    var expression =
                        CreateObjectQueryConstant(propInfo.GetValue(context, SetAccessBindingFlags, null, null, null));
                    if (expression != null)
                    {
                        return expression;
                    }
                }
            }

            return base.VisitMember(node);
        }
        private static string VisitMember(MemberExpression node, bool valueExpression = false)
        {
            if (node.Member is PropertyInfo && !valueExpression)
            {
                if (node.Expression is MemberExpression) return ((MemberExpression)node.Expression).Member.Name + "." + ((PropertyInfo)node.Member).GetName();
                return ((PropertyInfo) node.Member).GetName();
            }
            if (node.Expression == null) throw new NullReferenceException();

            object value;
            ConstantExpression captureConst;

            if (node.Expression is ConstantExpression)
            {
                captureConst = (ConstantExpression)node.Expression;
                value = ((FieldInfo)node.Member).GetValue(captureConst.Value);
            }
            else
            {
                MemberExpression memberConst = (MemberExpression)node.Expression;
                captureConst = (ConstantExpression)memberConst.Expression;
                value = ((PropertyInfo)node.Member).GetValue(((FieldInfo)memberConst.Member).GetValue(captureConst.Value));
            }

            if (value is string) return "'" + value + "'";
            if (value == null) return "null";
            throw new InvalidDataException();
        }
Exemple #16
0
 protected Expression MyVisitMember(MemberExpression node, string fieldName)
 {
     LambdaExpression lambda = Expression.Lambda(node);
     var fn = lambda.Compile();
     VisitConstant(Expression.Constant(fn.DynamicInvoke(null), node.Type), fieldName);
     return base.VisitMember(node);
 }
Exemple #17
0
 private void AddInclude(SimpleType source, MemberExpression memberSelector, LambdaExpression collectionInclude)
 {
     var members = source.GetAllMembers();
     if (members.Count > 0 && memberSelector.GetDepth() > 1)
     {
         var innermostMember = ExpressionUtil.GetInnermostMemberExpression(memberSelector);
         foreach (var kvp in members)
         {
             if (kvp.Key == innermostMember.Member)
             {
                 AddInclude(kvp.Value, ExpressionUtil.ReplaceInnermostMemberExpressionWithParameter(memberSelector) as MemberExpression, collectionInclude);
                 return;
             }
         }
     }
     else
     {
         var parameter = ExpressionUtil.GetParameterExpression(memberSelector);
         if (collectionInclude != null)
         {
             source.Includes.Add(IncludeDirectiveUtil.GetIncludeInCollectionDirective(memberSelector, collectionInclude));
         }
         else
         {
             source.Includes.Add(IncludeDirectiveUtil.GetIncludeDirective(memberSelector));
         }
     }
 }
 protected override Expression VisitMemberAccess(MemberExpression m)
 {
     string methodName = this.GetMethodName(m.Member.Name);
     MethodInfo method = m.Member.ReflectedType.GetMethod(methodName);
     this.AddMethod(method);
     return base.VisitMemberAccess(m);
 }
        protected override QueryNode VisitMemberAccess(MemberExpression expression)
        {
            if (expression.Expression == null)
                return base.VisitMemberAccess(expression);

            if (expression.Expression.NodeType == ExpressionType.Constant ||
                expression.Expression.NodeType == ExpressionType.Parameter ||
                expression.Expression.NodeType == ExpressionType.Convert)
                return base.VisitMemberAccess(expression);

            if (!(expression.Expression is MemberExpression))
                throw new NotSupportedException(string.Format("Unsupported member access. Expression type: {0}. Member name: {1}.", expression.Expression.NodeType, expression.Member.Name));

            QueryNode queryNode = VisitMemberAccess((MemberExpression)expression.Expression);

            // PATCH: this fixes querying on subproperties of result items (e.g. x=> x.Foo.Bar)
            var constant = queryNode as ConstantNode;

            if (constant != null) return new ConstantNode(expression.Member.GetValue(constant.Value), expression.Member.GetValueType());

            var field = queryNode as FieldNode;

            if (field != null)
            {
                // NOTE: later releases of SC7 change this behavior to include the property name in the field by default (e.g. x=>x.Foo.Bar would map to "foo.bar" in the index)
                // there may be some compatibility changes that go here later
                return new FieldNode(field.FieldKey, expression.Member.GetValueType()); // return a new FIELD, but set its effective type to the property's so there aren't comparison issues later
            }

            throw new NotSupportedException(string.Format("Unsupported member access. Expression type: {0}. Member name: {1}. Member Value Type: {2}", expression.Expression.NodeType, expression.Member.Name, queryNode.NodeType));
            // END PATCH
        }
 protected override Expression VisitMemberAccess(MemberExpression m) {
     if (m.Expression != null && m.Expression.NodeType == ExpressionType.Parameter) {
         sb.Append(m.Member.Name.ToLowerInvariant());
         return m;
     }
     throw new NotSupportedException(string.Format("The member '{0}' is not supported", m.Member.Name));
 }
 /// <inheritdoc/>
 public string GetFieldName(string prefix, MemberExpression memberExpression)
 {
     return
         memberExpression.Member.DeclaringType == typeof(ElasticFields)
             ? "_" + memberExpression.Member.Name.ToLowerInvariant()
             : wrapped.GetFieldName(prefix, memberExpression);
 }
        protected override Expression VisitMemberAccess(MemberExpression m)
        {
            if (m.Expression != null)
            {
                if (m.Expression.NodeType == ExpressionType.Constant)
                {
                    SetValue(m.GetValue());
                    return m;
                }
                if (m.Expression.NodeType == ExpressionType.Parameter)
                {
                    _currentKey = (m.Member.Name == "Id") ? "objectId" : m.Member.Name;

                    if (typeof(IParseUser).IsAssignableFrom(m.Expression.Type))
                        _currentKey = ParseUserContract.ResolveName(_currentKey);

                    if (!_where.ContainsKey(_currentKey))
                    {
                        if (m.Member is PropertyInfo && ((PropertyInfo)m.Member).PropertyType == typeof(bool))
                        {
                            _where[_currentKey] = !_inversed;
                        }
                        else
                        {
                            _where[_currentKey] = null;
                        }
                    }
                    return m;
                }
            }
            throw new NotSupportedException(string.Format("The member '{0}' is not supported", m.Member.Name));
        }
        protected override Expression VisitMember(MemberExpression node)
        {
            var memberExpression = node.Expression as MemberExpression;

            if (memberExpression != null)
            {
                if (!_uniquefList.Contains(memberExpression.ToString()))
                {
                    _uniquefList.Add(memberExpression.ToString());
                    var expression = _isNull
                        ? Expression.Constant(null, memberExpression.Type)
                        : (Expression)Expression.Default(memberExpression.Type);
                    if (CheckNullExpression == null)
                    {
                        CheckNullExpression = Expression.Equal(memberExpression, expression);
                    }
                    else
                    {
                        CheckNullExpression =
                            Expression.OrElse(Expression.Equal(memberExpression, expression),
                                CheckNullExpression);
                    }
                }
            }

            return base.VisitMember(node);
        }
        public static Predicate<object> GenerateEquals(MemberExpression prop, string value, Type type, ParameterExpression objParam)
        {
            BinaryExpression equalExpresion = null;
            if (TypeHelper.IsValueType(type))
            {
                object equalTypedInput = TypeHelper.ValueConvertor(type, value);
                if (equalTypedInput != null)
                {
                    var equalValue = System.Linq.Expressions.Expression.Constant(equalTypedInput, type);
                    equalExpresion = System.Linq.Expressions.Expression.Equal(prop, equalValue);
                }
            }
            else
            {
                var toStringExp = System.Linq.Expressions.Expression.Equal(ToLower(ToString(prop)), ExpressionHelper.ToLower(ExpressionHelper.ToString(System.Linq.Expressions.Expression.Constant(value))));
                equalExpresion = System.Linq.Expressions.Expression.AndAlso(ExpressionHelper.NotNull(prop), toStringExp);

            }
            if (equalExpresion != null)
            {
                Expression<Func<object, bool>> equalfunction = System.Linq.Expressions.Expression.Lambda<Func<object, bool>>(equalExpresion, objParam);
                return new Predicate<object>(equalfunction.Compile());
            }
            else
                return null;
        }
 /// <summary>
 ///     将属性变量转换成T-SQL字段名
 /// </summary>
 protected override Expression VisitMemberAccess(MemberExpression m)
 {
     base.VisitMemberAccess(m);
     if (_lst.Exists(o => o.Member.Name == m.Member.Name && o.Type == m.Type)) { return m; }
     _lst.Add(m);
     return m;
 }
        protected override Expression VisitMemberAccess(MemberExpression m)
        {
            Expression source = this.Visit(m.Expression);
            DbEntityExpression ex = source as DbEntityExpression;

            if (ex != null && this.mapping.IsAssociation(ex.Entity, m.Member))
            {
                DbProjectionExpression projection = (DbProjectionExpression)this.Visit(this.mapping.CreateMemberExpression(source, ex.Entity, m.Member));
                if (this.currentFrom != null && this.mapping.IsSingletonAssociation(ex.Entity, m.Member))
                {
                    // convert singleton associations directly to OUTER APPLY
                    projection = projection.AddOuterJoinTest();
                    Expression newFrom = new DbJoinExpression(DbJoinType.OuterApply, this.currentFrom, projection.Select, null);
                    this.currentFrom = newFrom;
                    return projection.Projector;
                }
                return projection;
            }
            else
            {
                Expression result = QueryBinder.BindMember(source, m.Member);
                MemberExpression mex = result as MemberExpression;
                if (mex != null && mex.Member == m.Member && mex.Expression == m.Expression)
                {
                    return m;
                }
                return result;
            }
        }
        public override BinaryExpression GetCompareExpression(MemberExpression propertyExpression, object userChoice)
        {
            var selectedValues = (IList<object>) userChoice;

            BinaryExpression contains = null;
            foreach (object o in selectedValues)
            {
                if (contains == null)
                {
                    contains = Expression.Equal(
                        propertyExpression,
                        Expression.Constant(o)
                        );
                    continue;
                }

                contains = Expression.OrElse(
                    contains,
                    Expression.Equal(
                        propertyExpression,
                        Expression.Constant(o)
                        ));
            }

            return contains;
        }
		protected override Expression VisitMemberAccess(MemberExpression m) {
			if (m.Member.DeclaringType == typeof(string)) {
				switch (m.Member.Name) {
					case "Length":
						sb.Append("LENGTH(");
						this.Visit(m.Expression);
						sb.Append(")");
						return m;
				}
			} else if (m.Member.DeclaringType == typeof(DateTime) || m.Member.DeclaringType == typeof(DateTimeOffset)) {
				switch (m.Member.Name) {
					case "Day":
						sb.Append("TO_CHAR(");
						this.Visit(m.Expression);
						sb.Append(", 'DD')");
						return m;
					case "Month":
						sb.Append("TO_CHAR(");
						this.Visit(m.Expression);
						sb.Append(", 'MM')");
						return m;
					case "Year":
						sb.Append("TO_CHAR(");
						this.Visit(m.Expression);
						sb.Append(", 'YYYY')");
						return m;
					case "Hour":
						sb.Append("TO_CHAR( ");
						this.Visit(m.Expression);
						sb.Append(", 'HH24')");
						return m;
					case "Minute":
						sb.Append("TO_CHAR( ");
						this.Visit(m.Expression);
						sb.Append(", 'MI')");
						return m;
					case "Second":
						sb.Append("TO_CHAR( ");
						this.Visit(m.Expression);
						sb.Append(", 'SS')");
						return m;
					case "Millisecond":
						sb.Append("TO_CHAR( ");
						this.Visit(m.Expression);
						sb.Append(", 'FF')");
						return m;
					case "DayOfWeek":
						sb.Append("(TO_CHAR(");
						this.Visit(m.Expression);
						sb.Append(", 'D') - 1)");
						return m;
					case "DayOfYear":
						sb.Append("(TO_CHAR( ");
						this.Visit(m.Expression);
						sb.Append(", 'DDD') - 1)");
						return m;
				}
			}
			throw new NotSupportedException(string.Format("The member '{0}' is not supported", m.Member.Name));
		}
        /// <summary>
        /// Determines whether the expression represents a supported member access call.
        /// </summary>
        /// <param name="expression">The expression.</param>
        /// <remarks></remarks>
        public override BindingSignatureSupport IsSupportedMember(MemberExpression expression)
        {
            // Account for if this is a schema access
            var memberParent = expression.Expression as MemberExpression;
            if (memberParent != null)
            {
                if (memberParent.Member.Name == "ContentType")
                {
                    switch (expression.Member.Name)
                    {
                        case "Alias":
                            return new BindingSignatureSupport(SignatureSupportType.SupportedAsSchemaAlias, ValuePredicateType.Equal);
                    }
                    return new BindingSignatureSupport(SignatureSupportType.SupportedAsSchemaMetaDataValue, ValuePredicateType.Equal);
                }
            }

            // If it's not schema, treat it like it's a field expression
            switch (expression.Member.Name)
            {
                case "Fields":
                    return new BindingSignatureSupport(SignatureSupportType.SupportedAsFieldName, ValuePredicateType.Equal);
            }

            return base.IsSupportedMember(expression);
        }
        protected override Expression VisitMember(MemberExpression node)
        {
            if (node.Expression != null && node.Expression.NodeType == ExpressionType.Parameter)
                return VisitFieldSelection(node);

            return base.VisitMember(node);
        }
		protected override Expression VisitMemberExpression(MemberExpression expression)
		{
			if (!IsMemberOfModel(expression))
			{
				return base.VisitMemberExpression(expression);
			}

			if (expression.Member.Name == "Key")
			{
				return _groupBy.KeySelector;
			}

			var elementSelector = _groupBy.ElementSelector;

			if ((elementSelector is MemberExpression) || (elementSelector is QuerySourceReferenceExpression))
			{
				// If ElementSelector is MemberExpression, just return
				return base.VisitMemberExpression(expression);
			}

			Expression result;
			// If ElementSelector is NewExpression, then search for member of name "get_" + originalMemberExpression.Member.Name
			if (TryFindTransparentPropertyOfAnonymousObject(elementSelector, expression.Member.Name, out result))
				return result;

			throw new NotImplementedException();
		}
Exemple #32
0
 protected override MSAst.Expression VisitMember(MSAst.MemberExpression node)
 {
     if (node == _globalContext)
     {
         return(PythonAst._globalContext);
     }
     return(base.VisitMember(node));
 }
Exemple #33
0
            /// <inheritdoc />
            protected override System.Linq.Expressions.Expression VisitMemberAccess(System.Linq.Expressions.MemberExpression m)
            {
                var result = base.VisitMemberAccess(m);

                currentNode = Expression.MakeMemberAccess(currentNode, m.Member);

                return(result);
            }
Exemple #34
0
        protected override System.Linq.Expressions.Expression BuildExpression(System.Linq.Expressions.MemberExpression property)
        {
            if (string.IsNullOrEmpty(this.SearchTerm))
            {
                return(null);
            }
            object enumValue = null;

            Expression searchExpression  = null;
            Expression searchExpression1 = null;
            Expression searchExpression2 = null;

            if (this.Comparator == EnumComparators.In)
            {
                Expression combinedExpression = null;
                foreach (string val in SearchTerm.Split(','))
                {
                    if (!ReferenceEquals(this.EnumType, null))
                    {
                        enumValue = Enum.Parse(this.EnumType, val);
                    }
                    else
                    {
                        enumValue = Enum.Parse(property.Type, val);
                    }
                    searchExpression1 = Expression.Equal(property, Expression.Constant(enumValue));
                    if (!ReferenceEquals(searchExpression1, null) && !ReferenceEquals(searchExpression2, null))
                    {
                        combinedExpression = Expression.OrElse(searchExpression2, searchExpression1);
                        searchExpression1  = combinedExpression;
                    }
                    searchExpression2 = searchExpression1;
                }
                if (ReferenceEquals(combinedExpression, null))
                {
                    combinedExpression = searchExpression2;
                }

                return(combinedExpression);
            }
            else
            {
                if (!ReferenceEquals(this.EnumType, null))
                {
                    enumValue = Enum.Parse(this.EnumType, this.SearchTerm);
                }
                else
                {
                    enumValue = Enum.Parse(property.Type, this.SearchTerm);
                }

                searchExpression = Expression.Equal(property, Expression.Constant(enumValue));
            }



            return(searchExpression);
        }
Exemple #35
0
        /// <summary>
        /// 表达式路由
        /// </summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        string ExpressionRouter(System.Linq.Expressions.Expression exp)
        {
            //获取实体列的特性
            List <EntityPropColumnAttributes> columnAttrList = AttributeHelper.GetEntityColumnAtrributes <TEntity>();

            string sb = string.Empty;

            if (exp is System.Linq.Expressions.BinaryExpression)//二元运算符
            {
                System.Linq.Expressions.BinaryExpression be = ((System.Linq.Expressions.BinaryExpression)exp);
                return(BinarExpressionProvider(be.Left, be.Right, be.NodeType));
            }
            else if (exp is System.Linq.Expressions.MemberExpression)//成员
            {
                System.Linq.Expressions.MemberExpression me = ((System.Linq.Expressions.MemberExpression)exp);
                return(me.Member.Name);
            }
            else if (exp is System.Linq.Expressions.NewArrayExpression)//数组
            {
                System.Linq.Expressions.NewArrayExpression ae = ((System.Linq.Expressions.NewArrayExpression)exp);
                StringBuilder tmpstr = new StringBuilder();
                foreach (System.Linq.Expressions.Expression ex in ae.Expressions)
                {
                    tmpstr.Append(ExpressionRouter(ex));
                    tmpstr.Append(",");
                }
                return(tmpstr.ToString(0, tmpstr.Length - 1));
            }
            else if (exp is System.Linq.Expressions.MethodCallExpression)//方法
            {
                return(MethodExpression(exp));
            }
            else if (exp is System.Linq.Expressions.ConstantExpression)
            {
                System.Linq.Expressions.ConstantExpression ce = ((System.Linq.Expressions.ConstantExpression)exp);
                if (ce.Value == null)
                {
                    return("null");
                }
                else if (ce.Value is ValueType)
                {
                    return(ce.Value.ToString());
                }
                else if (ce.Value is string || ce.Value is DateTime || ce.Value is char)
                {
                    //return string.Format("'{0}'", ce.Value.ToString());
                    return(string.Format("{0}", ce.Value.ToString()));
                }
            }
            else if (exp is System.Linq.Expressions.UnaryExpression)
            {
                System.Linq.Expressions.UnaryExpression ue = ((System.Linq.Expressions.UnaryExpression)exp);
                return(ExpressionRouter(ue.Operand));
            }
            return(null);
        }
 public static string GetMemberName <T>(Sle.Expression <Func <T, object> > expr)
 {
     Sle.Expression       body             = ((Sle.LambdaExpression)expr).Body;
     Sle.MemberExpression memberExpression = body as Sle.MemberExpression;
     if (memberExpression == null)
     {
         memberExpression = (Sle.MemberExpression)((Sle.UnaryExpression)body).Operand;
     }
     return(memberExpression.Member.Name);
 }
Exemple #37
0
        /// <summary>Default constructor with base <see cref="System.Linq.Expressions.MemberExpression" /> and <see cref="Remotion.Linq.Clauses.FromClauseBase" />.</summary>
        /// <param name="expression">Base member expression.</param>
        /// <param name="target">Target of the invocation.</param>
        internal EntityIdentifierExpression(System.Linq.Expressions.MemberExpression expression, Remotion.Linq.Clauses.FromClauseBase target)
            : base()
        {
            if (!(expression.Member is PropertyInfo))
            {
                throw new ArgumentOutOfRangeException("expression");
            }

            _expression = expression;
            _target     = target;
        }
Exemple #38
0
        public string GetPropertyNameFromExpression <TResult>(Expression <Func <TResult> > propertyExpression)
        {
            System.Linq.Expressions.MemberExpression memberExpression = (System.Linq.Expressions.MemberExpression)propertyExpression.Body;

            if (memberExpression != null)
            {
                return(memberExpression.Member.Name);
            }

            throw new ArgumentException("propertyExpression");
        }
Exemple #39
0
        protected override System.Linq.Expressions.Expression BuildExpression(System.Linq.Expressions.MemberExpression property)
        {
            if (this.SearchTerm == null)
            {
                return(null);
            }

            var enumValue = System.Enum.Parse(this.EnumType, this.SearchTerm);

            Expression searchExpression = Expression.Equal(property, Expression.Constant(enumValue));

            return(searchExpression);
        }
Exemple #40
0
            protected override LE.Expression VisitMemberAccess(LE.MemberExpression me, LE.Expression expr)
            {
                var pi = me.Member as PropertyInfo;

                if (pi != null && pi.PropertyType == typeof(String))
                {
                    var coalesceExpr = LE.Expression.Coalesce(me, LE.Expression.Constant(String.Empty));
                    return(coalesceExpr);
                }
                else
                {
                    return(base.VisitMemberAccess(me, expr));
                }
            }
Exemple #41
0
            /// <summary>
            /// Property access. Look to see if the parent type is one of these type of things.
            /// </summary>
            /// <param name="expression"></param>
            /// <returns></returns>
            protected override System.Linq.Expressions.Expression VisitMember(System.Linq.Expressions.MemberExpression expression)
            {
                //
                // If this is a property referencing an object, perhaps we can decode a short-circut of what was actually
                // meant.
                //

                var exprType = expression.Expression.Type;

                if (expression.Expression.NodeType == ExpressionType.New)
                {
                    // Is it a Tuple?
                    if (exprType.Name.StartsWith("Tuple`"))
                    {
                        int itemIndex = Convert.ToInt32(expression.Member.Name.Substring(4));
                        var newExpr   = expression.Expression as NewExpression;
                        DidRemove = true;
                        return(Visit(newExpr.Arguments[itemIndex - 1]));
                    }
                    if (exprType.Name.StartsWith("<>f__AnonymousType"))
                    {
                        DidRemove = true;
                        return(TranslateAnonymousPropertyReference(expression));
                    }
                }

                // If a user declared object is created and referenced (and the members are inited)
                // then we can use them as something to do translation in.
                // If this is an init expression, and the variable is not set, then that
                // is really bad - no one else is going to set it. Give the user enough infomration to debug it.
                if (expression.Expression.NodeType == ExpressionType.MemberInit)
                {
                    var result = TranslateUserObjectMemberInitReference(expression);
                    if (result == null)
                    {
                        throw new BadPropertyReferenceException($"Reference to property {expression.Member.Name} on object {expression.Expression.Type.Name} can't be translated because it isn't set in the initalizer expression.");
                    }
                    DidRemove = true;
                    return(result);
                }

                //
                // Fall through and perform default actions (like looking deeper) if we got
                // no where!
                //

                return(base.VisitMember(expression));
            }
Exemple #42
0
        public ExpressionBuilder(string parameter = "x", MemberExpression referenceExpression = null)
        {
            ResponseType = typeof(T);

            if (referenceExpression != null)
            {
                ModelType = ((PropertyInfo)referenceExpression.Member).PropertyType;
                Parameter = referenceExpression;
                paramExpresionVisitor.ReplaceParameter = Parameter;
            }
            else
            {
                ModelType = typeof(T);
                Parameter = Expression.Parameter(ModelType, parameter);
                paramExpresionVisitor.ReplaceParameter = Parameter;
            }
        }
        /// <summary>Default constructor with base <see cref="System.Linq.Expressions.MemberExpression" />, <see cref="IPropertyMapping" /> and <see cref="Remotion.Linq.Clauses.FromClauseBase" />.</summary>
        /// <param name="expression">Base member expression.</param>
        /// <param name="propertyMapping">Ontology property mapping.</param>
        /// <param name="target">Target of the invocation.</param>
        /// <param name="name">Name of the element in the property.</param>
        internal EntityPropertyExpression(System.Linq.Expressions.MemberExpression expression, IPropertyMapping propertyMapping, Remotion.Linq.Clauses.FromClauseBase target, string name)
            : base()
        {
            if (!(expression.Member is PropertyInfo))
            {
                throw new ArgumentOutOfRangeException("expression");
            }

            if (name.Length == 0)
            {
                throw new ArgumentOutOfRangeException("name");
            }

            _expression      = expression;
            _propertyMapping = propertyMapping;
            _target          = target;
            _name            = name;
        }
Exemple #44
0
        public string GetPropertyNameFromExpression <TResult>(Expression <Func <TResult> > propertyExpression)
        {
            if (propertyExpression == null)
            {
                throw new ArgumentNullException(nameof(propertyExpression));
            }

            System.Linq.Expressions.MemberExpression memberExpression = (System.Linq.Expressions.MemberExpression)propertyExpression.Body;

            if (memberExpression != null)
            {
                return(memberExpression.Member.Name);
            }
            else
            {
                throw new ArgumentException(nameof(propertyExpression));
            }
        }
Exemple #45
0
 /// <summary>
 /// Access of member, should create a projection and convert the expression.
 /// When we found a memberAccess we should substitute to a call to ourt
 /// object that implements projectionResult, so we should convert
 /// </summary>
 /// <param name="m"></param>
 protected override System.Linq.Expressions.Expression VisitMemberAccess(System.Linq.Expressions.MemberExpression m)
 {
     if (m.Expression.NodeType == System.Linq.Expressions.ExpressionType.Parameter)
     {
         String memberName = ComposeMemberAccess(m);
         projections.Add(projectionCreator(memberName));
         ProjectionsPropertyNames.Add(memberName);
         currentMemberAccess = String.Empty;
         return(LE.Expression.Convert( //Call the GetValue on row passing currentcolumnindex as argument.
                    LE.Expression.Call(
                        row,
                        miGetValue,
                        LE.Expression.Constant(currentColumnIndex++)),
                    m.Type));
     }
     else if (m.Expression.NodeType == System.Linq.Expressions.ExpressionType.MemberAccess)
     {
         ComposeMemberAccess(m);
     }
     return(base.VisitMemberAccess(m));
 }
Exemple #46
0
        public void SetPropertyValue <T>(Expression <Func <T> > expression, T value)
        {
            System.Linq.Expressions.MemberExpression exp = null;

            switch (expression.Body.NodeType)
            {
            case ExpressionType.Convert:
                exp = ((UnaryExpression)expression.Body).Operand as MemberExpression;
                break;

            case ExpressionType.MemberAccess:
                exp = (System.Linq.Expressions.MemberExpression)expression.Body;
                break;
            }

            if (exp == null)
            {
                throw new ArgumentException("expression");
            }

            this.SetPropertyValue <T>(exp.Member.Name, value);
        }
Exemple #47
0
        /// <summary>
        /// Handle a project
        /// </summary>
        /// <param name="m"></param>
        /// <param name="createProjection"></param>
        private LE.Expression HandleProjectionOfSingleElement(
            System.Linq.Expressions.MethodCallExpression m,
            Func <String, NHEX.IProjection> createProjection)
        {
            if (m.Arguments.Count == 2)
            {
                LE.LambdaExpression l  = (LE.LambdaExpression)Linq.Utils.Expression.StripQuotes(m.Arguments[1]);
                LE.MemberExpression me = (LE.MemberExpression)l.Body;

                String memberName = me.Member.Name;
                ProjectionsPropertyNames.Add(memberName);
                projections.Add(createProjection(memberName));

                return(LE.Expression.Convert(                 //Call the GetValue on row passing currentcolumnindex as argument.
                           LE.Expression.Call(
                               row,
                               miGetValue,
                               LE.Expression.Constant(currentColumnIndex++)),
                           me.Type));
            }
            return(m);
        }
 private static string SysExpression_Analyize <T, TSource>(SysLE.Expression <Func <T, TSource> > exp)
 {
     if (exp.Body.NodeType == SysLE.ExpressionType.Parameter)
     {
         return(exp.Name);
     }
     else if (exp.Body.NodeType == SysLE.ExpressionType.MemberAccess)
     {
         SysLE.MemberExpression mexp = (SysLE.MemberExpression)exp.Body;
         if (mexp == null)
         {
             return(string.Empty);
         }
         else
         {
             return(mexp.Member.Name);
         }
     }
     else
     {
         return(string.Empty);
     }
 }
 public MemberExpressionProxy(MemberExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
Exemple #50
0
 /// <summary>
 /// 获取某个变量的名称
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="memberExpression"></param>
 /// <returns></returns>
 public static string GetMemberName <T>(System.Linq.Expressions.Expression <System.Func <T> > memberExpression)
 {
     System.Linq.Expressions.MemberExpression expressionBody = (System.Linq.Expressions.MemberExpression)memberExpression.Body;
     Debug.Log(expressionBody.Member.Name);
     return(expressionBody.Member.Name);
 }
 protected internal override Expression VisitMember(MemberExpression node)
 {
     OutMember(node.Expression, node.Member);
     return(node);
 }
Exemple #52
0
 static string PropertyNameFromMemberExpr(Exprs.MemberExpression expr) => expr.Member.Name;
Exemple #53
0
 static Reflect.MemberInfo MemberFromExprMemberExpr(Exprs.MemberExpression expr) => expr.Member;
Exemple #54
0
 private String ComposeMemberAccess(System.Linq.Expressions.MemberExpression m)
 {
     currentMemberAccess = m.Member.Name +
                           (String.IsNullOrEmpty(currentMemberAccess) ? "" : "." + currentMemberAccess);
     return(currentMemberAccess);
 }
Exemple #55
0
 private Expression Convert(LinqExp.MemberExpression linqMemberAccess)
 {
     return(Expression.MakeMemberAccess(
                ConvertExp(linqMemberAccess.Expression),
                linqMemberAccess.Member));
 }
Exemple #56
0
        private static SysLE.Expression SysExpressionWhere_Analyize(SysLE.Expression exp, StringBuilder builder)
        {
            if (exp == null)
            {
                return(null);
            }

            SysLE.BinaryExpression binEx = exp as SysLE.BinaryExpression;
            if (binEx != null)
            {
                SysExpressionWhere_Analyize(binEx.Left, builder);
            }

            switch (exp.NodeType)
            {
            case SysLE.ExpressionType.Parameter:
            {
                SysLE.ParameterExpression param = (SysLE.ParameterExpression)exp;
                builder.Append("(" + param.Name);
                return(null);
            }

            case SysLE.ExpressionType.MemberAccess:
            {
                SysLE.MemberExpression mexp = (SysLE.MemberExpression)exp;
                builder.Append("(" + mexp.Member.Name);
                return(null);
            }

            case SysLE.ExpressionType.Constant:
            {
                SysLE.ConstantExpression cex = (SysLE.ConstantExpression)exp;
                if (cex.Value is string)
                {
                    builder.Append("'" + cex.Value.ToString() + "') ");
                }
                else
                {
                    builder.Append(cex.Value.ToString() + ")");
                }
                return(null);
            }

            default:
            {
                if (exp.NodeType == SysLE.ExpressionType.Equal)
                {
                    builder.Append("=");
                }
                else if (exp.NodeType == SysLE.ExpressionType.NotEqual)
                {
                    builder.Append("<>");
                }
                else if (exp.NodeType == SysLE.ExpressionType.LessThan)
                {
                    builder.Append("<");
                }
                else if (exp.NodeType == SysLE.ExpressionType.LessThanOrEqual)
                {
                    builder.Append("<=");
                }
                else if (exp.NodeType == SysLE.ExpressionType.GreaterThan)
                {
                    builder.Append(">");
                }
                else if (exp.NodeType == SysLE.ExpressionType.GreaterThanOrEqual)
                {
                    builder.Append(">=");
                }
                else if (exp.NodeType == SysLE.ExpressionType.AndAlso || exp.NodeType == SysLE.ExpressionType.And)
                {
                    builder.Append("and");
                }
                else if (exp.NodeType == SysLE.ExpressionType.OrElse || exp.NodeType == SysLE.ExpressionType.Or)
                {
                    builder.Append("or");
                }
            }
            break;
            }

            if (binEx != null)
            {
                SysExpressionWhere_Analyize(binEx.Right, builder);
            }

            return(binEx);
        }
 /// <summary>Default constructor with base <see cref="System.Linq.Expressions.MemberExpression" />, <see cref="IPropertyMapping" /> and <see cref="Remotion.Linq.Clauses.FromClauseBase" />.</summary>
 /// <param name="expression">Base member expression.</param>
 /// <param name="propertyMapping">Ontology property mapping.</param>
 /// <param name="target">Target of the invocation.</param>
 internal EntityPropertyExpression(System.Linq.Expressions.MemberExpression expression, IPropertyMapping propertyMapping, Remotion.Linq.Clauses.FromClauseBase target) :
     this(expression, propertyMapping, target, expression.Member.Name)
 {
 }
Exemple #58
0
 public static MemberExpression GetMemberAccess <T>(Expression <Func <T> > expr)
 {
     System.Linq.Expressions.MemberExpression mem = (System.Linq.Expressions.MemberExpression)expr.Body;
     return(mem);
 }
Exemple #59
0
        /// <summary>
        /// 生成表达式
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="parameter">参数表达式</param>
        /// <param name="member">成员表达式</param>
        /// <param name="value">属性值</param>
        /// <param name="operator">操作符</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="NotSupportedException"></exception>
        /// <returns></returns>
        public static Expression<Func<T, bool>> Create<T>(ParameterExpression parameter, MemberExpression member, object value, Operator @operator)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException(nameof(parameter));
            }
            if (member == null)
            {
                throw new ArgumentNullException(nameof(member));
            }
            switch (@operator)
            {
                case Operator.Contains:
                case Operator.EndWith:
                case Operator.StartsWith:
                    if (value != null && value.GetType() != typeof(string))
                    {
                        throw new NotSupportedException($"{nameof(Operator)}.{@operator}只适用于string类型");
                    }
                    var method = typeof(string).GetMethod(@operator.ToString(), new Type[] { typeof(string) });
                    var body = Expression.Call(member, method, ConstantExpression(value, typeof(string)));
                    return Expression.Lambda(body, parameter) as Expression<Func<T, bool>>;

                default:
                    var valueExp = ConstantExpression(value, member.Type);
                    var binaryBody = Expression.MakeBinary((ExpressionType)@operator, member, valueExp);
                    return Expression.Lambda(binaryBody, parameter) as Expression<Func<T, bool>>;
            }
        }
Exemple #60
0
 /// <summary>
 /// Visits the children of the <see cref="MemberExpression"/>.
 /// </summary>
 /// <param name="node">The expression to visit.</param>
 /// <returns>The modified expression, if it or any subexpression was modified;
 /// otherwise, returns the original expression.</returns>
 protected internal virtual Expression VisitMember(MemberExpression node)
 {
     return(node.Update(Visit(node.Expression)));
 }