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


C# Expressions.MemberInitExpression类代码示例

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


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

示例1: VisitMemberInit

        protected override Expression VisitMemberInit(MemberInitExpression node)
        {
            var bindings = node.Bindings.ToList();

            foreach (var binding in this.fromBindings)
            {
                if (bindings.All(o => o.Member.Name != binding.Member.Name) && binding.Member is PropertyInfo)
                {
                    var propertyInfo = binding.Member as PropertyInfo;

                    switch (propertyInfo.PropertyType.ToString())
                    {
                        case "System.String":
                            bindings.Add(Expression.Bind(binding.Member, Expression.Constant("")));
                            break;
                        case "System.Int32":
                        case "System.Int64":
                        case "System.Int16":
                            bindings.Add(Expression.Bind(binding.Member, Expression.Constant(0)));
                            break;
                        case "System.DateTime":
                            bindings.Add(Expression.Bind(binding.Member, Expression.Constant(DateTime.MinValue)));
                            break;
                    }
                }
            }

            return Expression.MemberInit(node.NewExpression, bindings);
        }
开发者ID:beyond-code-github,项目名称:xMap,代码行数:29,代码来源:AssignmentVisitor.cs

示例2: UpdateMemberInit

 protected MemberInitExpression UpdateMemberInit(MemberInitExpression init, NewExpression nex, IEnumerable<MemberBinding> bindings)
 {
     if (nex != init.NewExpression || bindings != init.Bindings) {
         return Expression.MemberInit(nex, bindings);
     }
     return init;
 }
开发者ID:sipsorcery,项目名称:sipsorcery,代码行数:7,代码来源:ExpressionVisitor.cs

示例3: VisitMemberInit

            protected override Expression VisitMemberInit(MemberInitExpression node)
            {
                if (node.NewExpression.NodeType == ExpressionType.New)
                    return node;

                return base.VisitMemberInit(node);
            }
开发者ID:ArthurYiL,项目名称:EntityFramework.Extended,代码行数:7,代码来源:Evaluator.cs

示例4: VisitMemberInit

 protected override Expression VisitMemberInit(MemberInitExpression node)
 {
     _classes.Push(node.Type);
     Expression visitMemberInit = base.VisitMemberInit(node);
     _classes.Pop();
     return visitMemberInit;
 }
开发者ID:kolupaev,项目名称:mongo-csharp-driver,代码行数:7,代码来源:UpdateExpressionVisitor.cs

示例5: VisitMemberInit

        protected override Expression VisitMemberInit(MemberInitExpression init)
        {
            if (this.mapping.IsEntity(init.Type))
            {
                var save = this.includeScope;
                this.includeScope = new ScopedDictionary<MemberInfo,bool>(this.includeScope);

                Dictionary<MemberInfo, MemberBinding> existing = init.Bindings.ToDictionary(b => b.Member);
                List<MemberBinding> newBindings = null;
                foreach (var mi in this.mapping.GetMappedMembers(init.Type))
                {
                    if (!existing.ContainsKey(mi) && this.mapping.IsRelationship(mi) && this.policy.IsIncluded(mi))
                    {
                        if (this.includeScope.ContainsKey(mi))
                        {
                            throw new NotSupportedException(string.Format("Cannot include '{0}.{1}' recursively.", mi.DeclaringType.Name, mi.Name));
                        }
                        Expression me = this.mapping.GetMemberExpression(init, mi);
                        if (newBindings == null)
                        {
                            newBindings = new List<MemberBinding>(init.Bindings);
                        }
                        newBindings.Add(Expression.Bind(mi, me));
                    }
                }
                if (newBindings != null)
                {
                    init = Expression.MemberInit(init.NewExpression, newBindings);
                }

                this.includeScope = save;
            }
            return base.VisitMemberInit(init);
        }
开发者ID:RyanDansie,项目名称:SubSonic-3.0,代码行数:34,代码来源:RelationshipIncluder.cs

示例6: VisitMemberInit

 protected override Expression VisitMemberInit(MemberInitExpression node)
 {
     // If we here, than eval the whole block failed, don't touch constructor!
     _allowEval = false;
     var newExpr = VisitAndConvert(node.NewExpression, "VisitMemberInit");
     _allowEval = true;
     // ReSharper disable once AssignNullToNotNullAttribute
     return node.Update(newExpr, Visit(node.Bindings, VisitMemberBinding));
 }
开发者ID:respu,项目名称:SimplyFast,代码行数:9,代码来源:PartialEvaluator.cs

示例7: Analyze

 private static void Analyze(MemberInitExpression mie, PathBox pb, DataServiceContext context)
 {
     if (ClientTypeUtil.TypeOrElementTypeIsEntity(mie.Type))
     {
         EntityProjectionAnalyzer.Analyze(mie, pb, context);
     }
     else
     {
         NonEntityProjectionAnalyzer.Analyze(mie, pb, context);
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:11,代码来源:ProjectionAnalyzer.cs

示例8: VisitMemberInit

            protected override Expression VisitMemberInit(MemberInitExpression node)
            {
                Expression newExpr = this.Visit(node.NewExpression);
                if (newExpr.NodeType == ExpressionType.Constant)
                {
                    // We translated the NewExpression to a ConstantExpression, so by-pass 
                    // VisitMemberInit's validation and return the expression as-is.
                    return newExpr;
                }

                return base.VisitMemberInit(node);
            }
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:12,代码来源:Evaluator.cs

示例9: VisitMemberInit

 protected override Expression VisitMemberInit(MemberInitExpression node)
 {
     foreach (MemberAssignment binding in node.Bindings)
     {
         var visitor = new MemberExpressionVisitor(Context);
         visitor.Visit(binding.Expression);
         visitor.SelectedColumn.Alias = binding.Member.Name;
         Columns.Add(visitor.SelectedColumn);
         Context.Columns.Add(binding.Member.Name, visitor.SelectedColumn);
     }
     return node;
 }
开发者ID:dusdong,项目名称:BaseComponent,代码行数:12,代码来源:SelectExpressionVisitor.cs

示例10: VisitMemberInit

 protected override Expression VisitMemberInit(MemberInitExpression node)
 {
     var results = new Dictionary<string, object>();
     foreach (MemberAssignment binding in node.Bindings)
     {
         var visitor = new MemberExpressionVisitor(Context);
         visitor.Visit(binding.Expression);
         if (visitor.Token.Type != TokenType.Object)
         {
             throw new NotSupportedException("不支持");
         }
         results.Add(binding.Member.Name, visitor.Token.Object);
     }
     Token = Token.Create(results);
     return node;
 }
开发者ID:dusdong,项目名称:BaseComponent,代码行数:16,代码来源:PropertyFieldExpressionVisitor.cs

示例11: VisitMemberInit

        protected override Expression VisitMemberInit(MemberInitExpression expression)
        {
            var projections = new List<SqlProjectionExpression>();
            foreach (var memberBinding in expression.Bindings)
            {
                var property = memberBinding as MemberAssignment;
                if (property == null)
                    continue;

                Visit(property.Expression);
                projections.Add(new SqlProjectionExpression((SqlColumnExpression)ast.Pop(), property.Member.Name));
            }

            ast.Push(new SqlSelectExpression(projections));

            return expression;
        }
开发者ID:dcga,项目名称:HybridDb,代码行数:17,代码来源:SelectParser.cs

示例12: BuildText

        /// <remarks>
        /// This build method caters to object initializers, like:
        /// 
        ///     new MyType { Foo = "Bar", Baz = "Qak" }
        /// 
        /// It does not however cater to anonymous types, as they don't compile
        /// down to traditional object initializers.
        /// 
        /// <see cref="BuildText(NewExpression)"/> caters to anonymous types.
        /// </remarks>
        string BuildText(MemberInitExpression expression)
        {
            if (expression.NewExpression.Constructor.GetParameters().Any())
                throw new ArgumentException(
                    "The result type must be constructed using a parameterless constructor. For example: n => new MyResultType { Foo = n.Bar }",
                    "expression");

            var bindingTexts = expression.Bindings.Select(binding =>
            {
                if (binding.BindingType != MemberBindingType.Assignment)
                    throw new ArgumentException("All bindings must be assignments. For example: n => new MyResultType { Foo = n.Bar }", "expression");

                var memberAssignment = (MemberAssignment)binding;
                return BuildStatement(memberAssignment.Expression, binding.Member);
            });

            return string.Join(", ", bindingTexts.ToArray());
        }
开发者ID:albumprinter,项目名称:Neo4jClient,代码行数:28,代码来源:CypherWithExpressionBuilder.cs

示例13: VisitMemberInit

			protected override Expression VisitMemberInit(MemberInitExpression init)
			{
				DoVisitNew(init.NewExpression);
				foreach (var x in init.Bindings)
				{
					var oldMembership = membershipPath;
					membershipPath = Expression.MakeMemberAccess(oldMembership, x.Member);
					this.VisitBinding(x);
					membershipPath = oldMembership;
				}

				assignments.Add(new AssignmentInformation()
				{
					Declaration = init,
					MembershipPath = membershipPath,
				});

				return init;
			}
开发者ID:viceroypenguin,项目名称:Complete.Data,代码行数:19,代码来源:ColumnExtractor.cs

示例14: Visit

		protected object Visit(MemberInitExpression expression)
		{
			var obj = this.Visit(expression.NewExpression);

			if (obj == InterpretFailed)
			{
				return obj;
			}

			foreach (var binding in expression.Bindings)
			{
				var value = this.Visit(obj, binding);

				if (value == InterpretFailed)
				{
					return value;
				}
			}

			return obj;
		}
开发者ID:tumtumtum,项目名称:Shaolinq,代码行数:21,代码来源:ExpressionInterpreter.cs

示例15: VisitMemberInit

        private void VisitMemberInit(MemberInitExpression node)
        {
            foreach (var memberBinding in node.Bindings)
            {
                var memberAssignment = memberBinding as MemberAssignment;
                if (memberAssignment != null)
                {
                    _mappings.Add(new ProjectionMemberMapping
                    {
                        Expression = memberAssignment.Expression,
                        Member = memberAssignment.Member
                    });
                }
                else
                {
                    var message = string.Format("Only member assignments are supported in a new expression in $project and $group, but found {0}.",
                        node.ToString());
                    throw new NotSupportedException(message);
                }
            }

            VisitNew(node.NewExpression);
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:23,代码来源:ProjectionMapper.cs


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