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


C# Expressions.MemberBinding类代码示例

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


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

示例1: TransformMixinMethodExpression

        /// <summary>
        /// Transforms a call to <code>entity.Mixin&lt;T&gt;()</code> to <code>new MixinType { Properties, ... }</code>
        /// </summary>
        /// <param name="method">The method call expression.</param>
        /// <returns>The</returns>
        public Expression TransformMixinMethodExpression(MethodCallExpression method)
        {
            var mixinType = method.Type;
            var entityType = method.Object.Type;
            string prefix = $"{mixinType.Name}_";

            // Get the available properties of the mixin.
            var entity = _model.GetEntityType(entityType);
            var properties = entity
                .GetProperties()
                .Where(p => p.Name.StartsWith(prefix))
                .ToArray();

            // Create an object initializer expression.
            var ctor = Expression.New(mixinType);
            var memberBindings = new MemberBinding[properties.Length];
            for (int i = 0; i < properties.Length; i++)
            {
                var property = properties[i];
                string propertyName = property.Name.Replace(prefix, "");
                var member = mixinType.GetProperty(propertyName);
                var value = Expression.Call(
                    EntityQueryModelVisitor.PropertyMethodInfo.MakeGenericMethod(member.PropertyType),
                    method.Object,
                    Expression.Constant(property.Name));

                memberBindings[i] = Expression.Bind(member, value);
            }

            return Expression.MemberInit(ctor, memberBindings);
        }
开发者ID:Antaris,项目名称:EntityFrameworkMixins,代码行数:36,代码来源:MixinExpressionVisitor.cs

示例2: CreateConstructorExpression

        public static CreateInstance CreateConstructorExpression(IContainerContext containerContext, ResolutionConstructor resolutionConstructor,
            ResolutionMember[] members = null)
        {
            var strategyParameter = Expression.Constant(containerContext.ResolutionStrategy, typeof(IResolutionStrategy));
            var resolutionInfoParameter = Expression.Parameter(typeof(ResolutionInfo), "resolutionInfo");

            var arguments = CreateExpressionFromResolutionTargets(resolutionConstructor.Parameters, strategyParameter, resolutionInfoParameter);

            var newExpression = Expression.New(resolutionConstructor.Constructor, arguments);

            if (members == null || members.Length == 0)
                return Expression.Lambda<CreateInstance>(newExpression, resolutionInfoParameter).Compile();

            var length = members.Length;
            var propertyExpressions = new MemberBinding[length];
            for (var i = 0; i < length; i++)
            {
                var member = members[i];
                var propertyExpression = Expression.Bind(member.MemberInfo,
                    CreateResolutionTargetExpression(member.ResolutionTarget, strategyParameter,
                        resolutionInfoParameter));
                propertyExpressions[i] = propertyExpression;

            }

            var initExpression = Expression.MemberInit(newExpression, propertyExpressions);
            return Expression.Lambda<CreateInstance>(initExpression, resolutionInfoParameter).Compile();
        }
开发者ID:z4kn4fein,项目名称:stashbox,代码行数:28,代码来源:ExpressionDelegateFactory.cs

示例3: CreateEditableMemberBinding

 public static EditableMemberBinding CreateEditableMemberBinding(MemberBinding member)
 {
     if (member is MemberAssignment) return new EditableMemberAssignment(member as MemberAssignment);
     else if (member is MemberListBinding) return new EditableMemberListBinding(member as MemberListBinding);
     else if (member is MemberMemberBinding) return new EditableMemberMemberBinding(member as MemberMemberBinding);
     else return null;
 }
开发者ID:juanplopes,项目名称:simple,代码行数:7,代码来源:EditableMemberBinding.cs

示例4: BindToProjectedWrapperMany

 private static void BindToProjectedWrapperMany(Expression[] bindingExpressions, int expressionStartIndex, MemberBinding[] bindings, int bindingStartIndex)
 {
     int propertyIndex = 0;
     while ((propertyIndex < (precreatedProjectedWrapperTypes.Length - 1)) && ((propertyIndex + expressionStartIndex) < bindingExpressions.Length))
     {
         bindings[bindingStartIndex + propertyIndex] = BindToProjectedProperty(typeof(ProjectedWrapperMany), propertyIndex, bindingExpressions[expressionStartIndex + propertyIndex]);
         propertyIndex++;
     }
     if (bindingExpressions.Length <= ((precreatedProjectedWrapperTypes.Length - 1) + expressionStartIndex))
     {
         while (propertyIndex < (precreatedProjectedWrapperTypes.Length - 1))
         {
             bindings[bindingStartIndex + propertyIndex] = BindToProjectedProperty(typeof(ProjectedWrapperMany), propertyIndex, Expression.Constant(string.Empty, typeof(string)));
             propertyIndex++;
         }
         bindings[(bindingStartIndex + precreatedProjectedWrapperTypes.Length) - 1] = Expression.Bind(typeof(ProjectedWrapperMany).GetProperty("Next"), Expression.MemberInit(Expression.New(typeof(ProjectedWrapperManyEnd)), new MemberBinding[] { Expression.Bind(typeof(ProjectedWrapperManyEnd).GetProperty("ResourceTypeName"), Expression.Constant(string.Empty, typeof(string))) }));
     }
     else
     {
         int length = bindingExpressions.Length - ((precreatedProjectedWrapperTypes.Length - 1) + expressionStartIndex);
         if (length > (precreatedProjectedWrapperTypes.Length - 1))
         {
             length = precreatedProjectedWrapperTypes.Length;
         }
         MemberBinding[] bindingArray = new MemberBinding[precreatedProjectedWrapperTypes.Length + 2];
         bindingArray[0] = Expression.Bind(typeof(ProjectedWrapperMany).GetProperty("ResourceTypeName"), Expression.Constant(string.Empty, typeof(string)));
         bindingArray[1] = Expression.Bind(typeof(ProjectedWrapperMany).GetProperty("PropertyNameList"), Expression.Constant(string.Empty, typeof(string)));
         BindToProjectedWrapperMany(bindingExpressions, (expressionStartIndex + precreatedProjectedWrapperTypes.Length) - 1, bindingArray, 2);
         Expression expression = Expression.MemberInit(Expression.New(typeof(ProjectedWrapperMany)), bindingArray);
         bindings[(bindingStartIndex + precreatedProjectedWrapperTypes.Length) - 1] = Expression.Bind(typeof(ProjectedWrapperMany).GetProperty("Next"), expression);
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:32,代码来源:ProjectedWrapper.cs

示例5: CreateExpression

        public static Expression CreateExpression(IContainerContext containerContext, ResolutionConstructor resolutionConstructor, ResolutionInfo resolutionInfo,
            Expression resolutionInfoExpression, ResolutionMember[] members = null)
        {
            var length = resolutionConstructor.Parameters.Length;
            var arguments = new Expression[length];

            for (var i = 0; i < length; i++)
            {
                var parameter = resolutionConstructor.Parameters[i];
                arguments[i] = containerContext.ResolutionStrategy.GetExpressionForResolutionTarget(parameter, resolutionInfo, resolutionInfoExpression);
            }

            var newExpression = Expression.New(resolutionConstructor.Constructor, arguments);

            if (members == null || members.Length == 0) return newExpression;
            {
                var propLength = members.Length;
                var propertyExpressions = new MemberBinding[propLength];
                for (var i = 0; i < propLength; i++)
                {
                    var member = members[i];
                    var propertyExpression = Expression.Bind(member.MemberInfo,
                        containerContext.ResolutionStrategy.GetExpressionForResolutionTarget(member.ResolutionTarget, resolutionInfo, resolutionInfoExpression));
                    propertyExpressions[i] = propertyExpression;
                }

                return Expression.MemberInit(newExpression, propertyExpressions);
            }
        }
开发者ID:z4kn4fein,项目名称:stashbox,代码行数:29,代码来源:ExpressionDelegateFactory.cs

示例6: VisitMemberBinding

        protected override MemberBinding VisitMemberBinding(MemberBinding memberBinding)
        {
            if(memberBinding.BindingType == MemberBindingType.Assignment)
            {
#if PORTABLE
                var propertyInfo = memberBinding.Member as PropertyInfo;
                var assignment = memberBinding as MemberAssignment;
                if (propertyInfo != null 
                    && assignment != null 
                    && assignment.Expression.Type.IsValueType 
                    && !propertyInfo.PropertyType.IsValueType)
                {
                    var valueExpression = Expression.TypeAs(VisitExpression(assignment.Expression), propertyInfo.PropertyType);
                    return Expression.Bind(memberBinding.Member, valueExpression);
                }
#else
                if (memberBinding.Member.MemberType == MemberTypes.Property)
                {
                    var propertyInfo = memberBinding.Member as PropertyInfo;
                    var assignment = memberBinding as MemberAssignment;
                    if (assignment.Expression.Type.IsValueType && !propertyInfo.PropertyType.IsValueType)
                    {
                        var valueExpression = Expression.TypeAs(VisitExpression(assignment.Expression), propertyInfo.PropertyType);
                        return Expression.Bind(memberBinding.Member, valueExpression);
                    }
                }
#endif
            }
            return base.VisitMemberBinding(memberBinding);
        }
开发者ID:GTuritto,项目名称:BrightstarDB,代码行数:30,代码来源:SparqlGeneratorSelectExpressionBuilder.cs

示例7: VisitBinding

 protected override MemberBinding VisitBinding(MemberBinding binding)
 {
     var save = receivingMember;
     receivingMember = binding.Member;
     var result = base.VisitBinding(binding);
     receivingMember = save;
     return result;
 }
开发者ID:ScottWeinstein,项目名称:Linq2KdbQ,代码行数:8,代码来源:QExecutionBuilder.cs

示例8: VisitBinding

        protected override MemberBinding VisitBinding(MemberBinding node)
        {
            var elementName = BsonClassMap.LookupClassMap(_classes.Peek()).GetMemberMap(node.Member.Name).ElementName;
            _assigments.Push(elementName);

            MemberBinding visitMemberBinding = base.VisitBinding(node);
            _assigments.Pop();
            return visitMemberBinding;
        }
开发者ID:kolupaev,项目名称:mongo-csharp-driver,代码行数:9,代码来源:UpdateExpressionVisitor.cs

示例9: Decode

 public MemberBinding[] Decode(ref byte* data, ref int remainingBytes, bool doNotCheckBounds)
 {
     int count = intCodec.Decode(ref data, ref remainingBytes, doNotCheckBounds);
     if (count == -1)
         return null;
     var result = new MemberBinding[count];
     for (int i = 0; i < count; i++)
         result[i] = memberBindingCodec.Decode(ref data, ref remainingBytes, doNotCheckBounds);
     return result;
 }
开发者ID:yonglehou,项目名称:SharpRPC,代码行数:10,代码来源:MemberBindingCollectionCodec.cs

示例10: GetMutator

 public static IMemberBindingMutator GetMutator(MemberBinding memberBinding)
 {
     if (memberBinding is MemberAssignment)
         return new MemberAssignmentMutator((MemberAssignment)memberBinding);
     if (memberBinding is MemberMemberBinding)
         return new MemberMemberBindingMutator((MemberMemberBinding)memberBinding);
     if (memberBinding is MemberListBinding)
         return new MemberListBindingMutator((MemberListBinding)memberBinding);
     throw Error.BadArgument("S0040: Unknown Expression Type '{0}'", memberBinding.GetType());
 }
开发者ID:TheRealDuckboy,项目名称:mono-soc-2008,代码行数:10,代码来源:MemberBindingMutatorFactory.cs

示例11: VisitBinding

		protected virtual MemberBinding VisitBinding (MemberBinding binding)
		{
			switch (binding.BindingType)
			{
				case MemberBindingType.Assignment:
					return VisitMemberAssignment ((MemberAssignment)binding);
				default:
					throw new ArgumentException (string.Format ("Unhandled binding type '{0}'", binding.BindingType));
			}
		}
开发者ID:kstreet,项目名称:Street.MvxPlugins,代码行数:10,代码来源:ExpressionVisitor.cs

示例12: ReduceMemberBinding

 internal static Expression ReduceMemberBinding(ParameterExpression objVar, MemberBinding binding) {
     MemberExpression member = Expression.MakeMemberAccess(objVar, binding.Member);
     switch (binding.BindingType) {
         case MemberBindingType.Assignment:
             return Expression.Assign(member, ((MemberAssignment)binding).Expression);
         case MemberBindingType.ListBinding:
             return ReduceListInit(member, ((MemberListBinding)binding).Initializers, false);
         case MemberBindingType.MemberBinding:
             return ReduceMemberInit(member, ((MemberMemberBinding)binding).Bindings, false);
         default: throw Assert.Unreachable;
     }
 }
开发者ID:mscottford,项目名称:ironruby,代码行数:12,代码来源:MemberInitExpression.cs

示例13: VisitBinding

		internal virtual MemberBinding VisitBinding(MemberBinding binding) {
			switch (binding.BindingType) {
				case MemberBindingType.Assignment:
					return this.VisitMemberAssignment((MemberAssignment)binding);
				case MemberBindingType.MemberBinding:
					return this.VisitMemberMemberBinding((MemberMemberBinding)binding);
				case MemberBindingType.ListBinding:
					return this.VisitMemberListBinding((MemberListBinding)binding);
				default:
					throw Error.UnhandledBindingType(binding.BindingType);
			}
		}
开发者ID:modulexcite,项目名称:LinqToSQL2,代码行数:12,代码来源:ExpressionVisitor.cs

示例14: VisitBinding

 protected virtual MemberBinding VisitBinding(MemberBinding binding)
 {
     switch (binding.BindingType)
     {
         case MemberBindingType.Assignment:
             return this.VisitMemberAssignment((MemberAssignment)binding);
         case MemberBindingType.MemberBinding:
             return this.VisitMemberMemberBinding((MemberMemberBinding)binding);
         case MemberBindingType.ListBinding:
             return this.VisitMemberListBinding((MemberListBinding)binding);
         default:
             throw new Exception($"Unhandled binding type '{binding.BindingType}'");
     }
 }
开发者ID:ServiceStack,项目名称:ServiceStack.OrmLite,代码行数:14,代码来源:SqlExpressionVisitor.cs

示例15: VisitBinding

		protected virtual MemberBinding VisitBinding(MemberBinding binding, Stack<string> stack, Stack<IElasticPropertyAttribute> properties)
		{
			switch (binding.BindingType)
			{
				case MemberBindingType.Assignment:
					return this.VisitMemberAssignment((MemberAssignment)binding, stack, properties);
				case MemberBindingType.MemberBinding:
					return this.VisitMemberMemberBinding((MemberMemberBinding)binding, stack, properties);
				case MemberBindingType.ListBinding:
					return this.VisitMemberListBinding((MemberListBinding)binding, stack, properties);
				default:
					throw new Exception(string.Format("Unhandled binding type '{0}'", binding.BindingType));
			}
		}
开发者ID:BiYiTuan,项目名称:elasticsearch-net,代码行数:14,代码来源:ExpressionVisitor.cs


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