当前位置: 首页>>代码示例>>C#>>正文


C# Expressions.MemberExpression类代码示例

本文整理汇总了C#中System.Linq.Expressions.MemberExpression的典型用法代码示例。如果您正苦于以下问题:C# MemberExpression类的具体用法?C# MemberExpression怎么用?C# MemberExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MemberExpression类属于System.Linq.Expressions命名空间,在下文中一共展示了MemberExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VisitMemberAccess

 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);
 }
开发者ID:hhahh2011,项目名称:CH.Cms,代码行数:7,代码来源:DMapperRuleAnalyzer.cs

示例2: VisitMember

        /// <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);
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:34,代码来源:DbQueryVisitor.cs

示例3: VisitMember

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

            return base.VisitMember(node);
        }
开发者ID:jarlrasm,项目名称:ElasticLINQ,代码行数:7,代码来源:MemberProjectionExpressionVisitor.cs

示例4: VisitMember

        /// <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);
        }
开发者ID:peschuster,项目名称:PropertyTranslator,代码行数:31,代码来源:PropertyVisitor.cs

示例5: VisitMember

        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);
        }
开发者ID:shay1e,项目名称:ExpressMapper,代码行数:27,代码来源:NullCheckNestedMemberVisitor.cs

示例6: VisitMemberAccess

        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
        }
开发者ID:simonproctor,项目名称:Synthesis,代码行数:32,代码来源:BugFixExpressionParser.cs

示例7: VisitMemberAccess

        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;
            }
        }
开发者ID:jaykizhou,项目名称:elinq,代码行数:30,代码来源:RelationshipBinder.cs

示例8: VisitMemberAccess

        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;
            }
        }
开发者ID:radischevo,项目名称:Radischevo.Wahha,代码行数:29,代码来源:RelationshipBinder.cs

示例9: VisitMemberAccess

 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);
 }
开发者ID:jbowwww,项目名称:ArtefactService,代码行数:28,代码来源:ServerQueryVisitor.cs

示例10: GenerateEquals

        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;
        }
开发者ID:vahtel65,项目名称:Aspect_loc,代码行数:26,代码来源:ExpressionHelper.cs

示例11: VisitMember

 protected override Expression VisitMember(MemberExpression node)
 {
     var visitor = new MemberExpressionVisitor(this.Context);
     visitor.Visit(node);
     Column = visitor.Column;
     return node;
 }
开发者ID:BeanHsiang,项目名称:Greedy,代码行数:7,代码来源:BinaryExpressionVisitor.cs

示例12: VisitMemberAccess

 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));
 }
开发者ID:idkay0,项目名称:Unity-QuickSheet,代码行数:7,代码来源:WhereTranslator.cs

示例13: VisitMemberAccess

        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);
        }
开发者ID:ArsenShnurkov,项目名称:deveeldb,代码行数:35,代码来源:DeveelDbFormatter.cs

示例14: GetCompareExpression

        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;
        }
开发者ID:rajeshgajra19889,项目名称:faceted-search,代码行数:26,代码来源:MultipleValueMapper.cs

示例15: VisitMemberExpression

		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();
		}
开发者ID:liypeng,项目名称:nhibernate-core,代码行数:29,代码来源:GroupBySelectClauseRewriter.cs


注:本文中的System.Linq.Expressions.MemberExpression类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。