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


C# ExpressionResolutionResult类代码示例

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


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

示例1: BindNullableExpression

        private static MemberAssignment BindNullableExpression(PropertyMap propertyMap,
            ExpressionResolutionResult result)
        {
            if (result.ResolutionExpression.NodeType == ExpressionType.MemberAccess)
            {
                var memberExpr = (MemberExpression) result.ResolutionExpression;
                if (memberExpr.Expression != null && memberExpr.Expression.NodeType == ExpressionType.MemberAccess)
                {
                    var destType = propertyMap.DestinationPropertyType;
                    var parentExpr = memberExpr.Expression;
                    Expression expressionToBind = Expression.Convert(memberExpr, destType);
                    var nullExpression = Expression.Convert(Expression.Constant(null), destType);
                    while (parentExpr.NodeType != ExpressionType.Parameter)
                    {
                        memberExpr = (MemberExpression) memberExpr.Expression;
                        parentExpr = memberExpr.Expression;
                        expressionToBind = Expression.Condition(
                            Expression.Equal(memberExpr, Expression.Constant(null)),
                            nullExpression,
                            expressionToBind
                            );
                    }

                    return Expression.Bind(propertyMap.DestinationProperty.MemberInfo, expressionToBind);
                }
            }

            return Expression.Bind(propertyMap.DestinationProperty.MemberInfo,
                Expression.Convert(result.ResolutionExpression, propertyMap.DestinationPropertyType));
        }
开发者ID:garora,项目名称:AutoMapper,代码行数:30,代码来源:NullableExpressionBinder.cs

示例2: BindEnumerableExpression

        private static MemberAssignment BindEnumerableExpression(IConfigurationProvider configuration, PropertyMap propertyMap, ExpressionRequest request, ExpressionResolutionResult result, ConcurrentDictionary<ExpressionRequest, int> typePairCount)
        {
            var destinationListType = TypeHelper.GetElementType(propertyMap.DestinationPropertyType);
            var sourceListType = TypeHelper.GetElementType(propertyMap.SourceType);
            var expression = result.ResolutionExpression;

            if (sourceListType != destinationListType)
            {
                var listTypePair = new ExpressionRequest(sourceListType, destinationListType, request.MembersToExpand);
                var transformedExpression = configuration.ExpressionBuilder.CreateMapExpression(listTypePair, typePairCount);
                if(transformedExpression == null)
                {
                    return null;
                }
                expression = Expression.Call(typeof (Enumerable), "Select", new[] {sourceListType, destinationListType}, result.ResolutionExpression, transformedExpression);
            }

            expression = Expression.Call(typeof(Enumerable), propertyMap.DestinationPropertyType.IsArray ? "ToArray" : "ToList", new[] { destinationListType }, expression);

            if(configuration.Configuration.AllowNullCollections) {
                expression = Expression.Condition(
                            Expression.NotEqual(
                                Expression.TypeAs(result.ResolutionExpression, typeof(object)),
                                Expression.Constant(null)),
                            expression,
                            Expression.Constant(null, propertyMap.DestinationPropertyType));
            }

            return Expression.Bind(propertyMap.DestinationProperty, expression);
        }
开发者ID:RahmanM,项目名称:AutoMapper,代码行数:30,代码来源:EnumerableExpressionBinder.cs

示例3: BindEnumerableExpression

        private static MemberAssignment BindEnumerableExpression(IMappingEngine mappingEngine, PropertyMap propertyMap,
            ExpressionRequest request, ExpressionResolutionResult result,
            Internal.IDictionary<ExpressionRequest, int> typePairCount)
        {
            MemberAssignment bindExpression;
            Type destinationListType = GetDestinationListTypeFor(propertyMap);
            Type sourceListType = null;
            // is list

            if (result.Type.IsArray)
            {
                sourceListType = result.Type.GetElementType();
            }
            else
            {
                sourceListType = result.Type.GetGenericArguments().First();
            }
            var listTypePair = new ExpressionRequest(sourceListType, destinationListType, request.IncludedMembers);

            var selectExpression = result.ResolutionExpression;
            if (sourceListType != destinationListType)
            {
                var transformedExpression = Extensions.CreateMapExpression(mappingEngine, listTypePair, typePairCount);
                selectExpression = Expression.Call(
                    typeof (Enumerable),
                    "Select",
                    new[] {sourceListType, destinationListType},
                    result.ResolutionExpression,
                    transformedExpression);
            }

            if (typeof (IList<>).MakeGenericType(destinationListType)
                .IsAssignableFrom(propertyMap.DestinationPropertyType)
                ||
                typeof (ICollection<>).MakeGenericType(destinationListType)
                    .IsAssignableFrom(propertyMap.DestinationPropertyType))
            {
                // Call .ToList() on IEnumerable
                var toListCallExpression = GetToListCallExpression(propertyMap, destinationListType, selectExpression);

                bindExpression = Expression.Bind(propertyMap.DestinationProperty.MemberInfo, toListCallExpression);
            }
            else if (propertyMap.DestinationPropertyType.IsArray)
            {
                // Call .ToArray() on IEnumerable
                MethodCallExpression toArrayCallExpression = Expression.Call(
                    typeof (Enumerable),
                    "ToArray",
                    new[] {destinationListType},
                    selectExpression);
                bindExpression = Expression.Bind(propertyMap.DestinationProperty.MemberInfo, toArrayCallExpression);
            }
            else
            {
                // destination type implements ienumerable, but is not an ilist. allow deferred enumeration
                bindExpression = Expression.Bind(propertyMap.DestinationProperty.MemberInfo, selectExpression);
            }
            return bindExpression;
        }
开发者ID:AnatolyKulakov,项目名称:AutoMapper,代码行数:59,代码来源:EnumerableExpressionBinder.cs

示例4: BindCustomProjectionExpression

        private static MemberAssignment BindCustomProjectionExpression(PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionResolutionResult result)
        {
            var visitor = new ParameterReplacementVisitor(result.ResolutionExpression);

            var replaced = visitor.Visit(propertyTypeMap.CustomProjection.Body);

            return Expression.Bind(propertyMap.DestinationProperty.MemberInfo, replaced);
        }
开发者ID:gonzalogilrepositorio,项目名称:Proyecto-ComIT,代码行数:8,代码来源:CustomProjectionExpressionBinder.cs

示例5: ExpressionResolutionResult

        private static ExpressionResolutionResult ExpressionResolutionResult(
            ExpressionResolutionResult expressionResolutionResult, LambdaExpression lambdaExpression)
        {
            Expression currentChild = lambdaExpression.ReplaceParameters(expressionResolutionResult.ResolutionExpression);
            Type currentChildType = currentChild.Type;

            return new ExpressionResolutionResult(currentChild, currentChildType);
        }
开发者ID:284247028,项目名称:AutoMapper,代码行数:8,代码来源:MemberResolverExpressionResultConverter.cs

示例6: BindEnumerableExpression

        private static MemberAssignment BindEnumerableExpression(IConfigurationProvider configuration, PropertyMap propertyMap, ExpressionRequest request, ExpressionResolutionResult result, ConcurrentDictionary<ExpressionRequest, int> typePairCount)
        {
            var destinationListType = GetDestinationListTypeFor(propertyMap);

            var sourceListType = result.Type.IsArray ? result.Type.GetElementType() : result.Type.GetTypeInfo().GenericTypeArguments.First();
            var listTypePair = new ExpressionRequest(sourceListType, destinationListType, request.MembersToExpand);

            Expression exp = result.ResolutionExpression;

            if (sourceListType != destinationListType)
            {
                var transformedExpression = configuration.ExpressionBuilder.CreateMapExpression(listTypePair, typePairCount);
                if(transformedExpression == null)
                {
                    return null;
                }
                exp = Expression.Call(
                        typeof (Enumerable),
                        "Select",
                        new[] {sourceListType, destinationListType},
                        result.ResolutionExpression,
                        transformedExpression);
            }
            

            if (typeof (IList<>).MakeGenericType(destinationListType)
                .GetTypeInfo().IsAssignableFrom(propertyMap.DestinationPropertyType.GetTypeInfo())
                ||
                typeof (ICollection<>).MakeGenericType(destinationListType)
                    .GetTypeInfo().IsAssignableFrom(propertyMap.DestinationPropertyType.GetTypeInfo()))
            {
                // Call .ToList() on IEnumerable
                exp = GetToListCallExpression(propertyMap, destinationListType, exp);                
            }
            else if (propertyMap.DestinationPropertyType.IsArray)
            {
                // Call .ToArray() on IEnumerable
                exp = Expression.Call(
                        typeof (Enumerable),
                        "ToArray",
                        new[] {destinationListType},
                        exp);
            }
            
            if(configuration.AllowNullCollections) {
                exp = Expression.Condition(
                            Expression.NotEqual(
                                Expression.TypeAs(result.ResolutionExpression, typeof(object)), 
                                Expression.Constant(null)),
                            exp,
                            Expression.Constant(null, propertyMap.DestinationPropertyType));
            }

            return Expression.Bind(propertyMap.DestinationProperty.MemberInfo, exp);
        }
开发者ID:284247028,项目名称:AutoMapper,代码行数:55,代码来源:EnumerableExpressionBinder.cs

示例7: ExpressionResolutionResult

        private static ExpressionResolutionResult ExpressionResolutionResult(
            ExpressionResolutionResult expressionResolutionResult, LambdaExpression lambdaExpression)
        {
            var oldParameter = lambdaExpression.Parameters.Single();
            var newParameter = expressionResolutionResult.ResolutionExpression;
            var converter = new ParameterConversionVisitor(newParameter, oldParameter);

            Expression currentChild = converter.Visit(lambdaExpression.Body);
            Type currentChildType = currentChild.Type;

            return new ExpressionResolutionResult(currentChild, currentChildType);
        }
开发者ID:garora,项目名称:AutoMapper,代码行数:12,代码来源:MemberResolverExpressionResultConverter.cs

示例8: BindEnumerableExpression

        private static MemberAssignment BindEnumerableExpression(IConfigurationProvider configuration, PropertyMap propertyMap, ExpressionRequest request, ExpressionResolutionResult result, ConcurrentDictionary<ExpressionRequest, int> typePairCount)
        {
            MemberAssignment bindExpression;
            Type destinationListType = GetDestinationListTypeFor(propertyMap);

            var sourceListType = result.Type.IsArray ? result.Type.GetElementType() : result.Type.GetTypeInfo().GenericTypeArguments.First();
            var listTypePair = new ExpressionRequest(sourceListType, destinationListType, request.MembersToExpand);

            var selectExpression = result.ResolutionExpression;
            if (sourceListType != destinationListType)
            {
                var transformedExpression = configuration.ExpressionBuilder.CreateMapExpression(listTypePair, typePairCount);
                if(transformedExpression == null)
                {
                    return null;
                }
                selectExpression = Expression.Call(
                    typeof (Enumerable),
                    "Select",
                    new[] {sourceListType, destinationListType},
                    result.ResolutionExpression,
                    transformedExpression);
            }

            if (typeof (IList<>).MakeGenericType(destinationListType)
                .GetTypeInfo().IsAssignableFrom(propertyMap.DestinationPropertyType.GetTypeInfo())
                ||
                typeof (ICollection<>).MakeGenericType(destinationListType)
                    .GetTypeInfo().IsAssignableFrom(propertyMap.DestinationPropertyType.GetTypeInfo()))
            {
                // Call .ToList() on IEnumerable
                var toListCallExpression = GetToListCallExpression(propertyMap, destinationListType, selectExpression);

                bindExpression = Expression.Bind(propertyMap.DestinationProperty.MemberInfo, toListCallExpression);
            }
            else if (propertyMap.DestinationPropertyType.IsArray)
            {
                // Call .ToArray() on IEnumerable
                MethodCallExpression toArrayCallExpression = Expression.Call(
                    typeof (Enumerable),
                    "ToArray",
                    new[] {destinationListType},
                    selectExpression);
                bindExpression = Expression.Bind(propertyMap.DestinationProperty.MemberInfo, toArrayCallExpression);
            }
            else
            {
                // destination type implements ienumerable, but is not an ilist. allow deferred enumeration
                bindExpression = Expression.Bind(propertyMap.DestinationProperty.MemberInfo, selectExpression);
            }
            return bindExpression;
        }
开发者ID:garora,项目名称:AutoMapper,代码行数:52,代码来源:EnumerableExpressionBinder.cs

示例9: ExpressionResolutionResult

        private static ExpressionResolutionResult ExpressionResolutionResult(
            ExpressionResolutionResult expressionResolutionResult, MemberInfo getter)
        {
            Expression currentChild = expressionResolutionResult.ResolutionExpression;
            Type currentChildType;

            var propertyInfo = getter as PropertyInfo;
            if (propertyInfo != null)
            {
                currentChild = Expression.Property(currentChild, propertyInfo);
                currentChildType = propertyInfo.PropertyType;
            }
            else
                currentChildType = currentChild.Type;

            return new ExpressionResolutionResult(currentChild, currentChildType);
        }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:17,代码来源:MemberGetterExpressionResultConverter.cs

示例10: BindMappedTypeExpression

        private static MemberAssignment BindMappedTypeExpression(IMappingEngine mappingEngine, PropertyMap propertyMap,
            ExpressionRequest request, ExpressionResolutionResult result, Internal.IDictionary<ExpressionRequest, int> typePairCount)
        {
            var transformedExpression = ((IMappingEngineRunner)mappingEngine).CreateMapExpression(request, result.ResolutionExpression, typePairCount);

            // Handles null source property so it will not create an object with possible non-nullable propeerties
            // which would result in an exception.
            if (mappingEngine.ConfigurationProvider.MapNullSourceValuesAsNull)
            {
                var expressionNull = Expression.Constant(null, propertyMap.DestinationPropertyType);
                transformedExpression =
                    Expression.Condition(Expression.NotEqual(result.ResolutionExpression, Expression.Constant(null)),
                        transformedExpression, expressionNull);
            }

            return Expression.Bind(propertyMap.DestinationProperty.MemberInfo, transformedExpression);
        }
开发者ID:redwyre,项目名称:AutoMapper,代码行数:17,代码来源:MappedTypeExpressionBinder.cs

示例11: GetExpressionResolutionResult

        public ExpressionResolutionResult GetExpressionResolutionResult(ExpressionResolutionResult expressionResolutionResult, PropertyMap propertyMap, IValueResolver valueResolver)
        {
            Expression currentChild = expressionResolutionResult.ResolutionExpression;
            Type currentChildType;
            var getter = (IMemberGetter)valueResolver;
            var memberInfo = getter.MemberInfo;

            var propertyInfo = memberInfo as PropertyInfo;
            if (propertyInfo != null)
            {
                currentChild = Expression.Property(currentChild, propertyInfo);
                currentChildType = propertyInfo.PropertyType;
            }
            else
                currentChildType = currentChild.Type;

            return new ExpressionResolutionResult(currentChild, currentChildType);
        }
开发者ID:dennyli,项目名称:HandySolution,代码行数:18,代码来源:MemberGetterExpressionResultConverter.cs

示例12: BindMappedTypeExpression

        private static MemberAssignment BindMappedTypeExpression(IConfigurationProvider configuration, PropertyMap propertyMap, ExpressionRequest request, ExpressionResolutionResult result, IDictionary<ExpressionRequest, int> typePairCount)
        {
            var transformedExpression = configuration.ExpressionBuilder.CreateMapExpression(request, result.ResolutionExpression, typePairCount);
            if(transformedExpression == null)
            {
                return null;
            }
            // Handles null source property so it will not create an object with possible non-nullable propeerties 
            // which would result in an exception.
            if (propertyMap.TypeMap.Profile.AllowNullDestinationValues && !propertyMap.AllowNull)
            {
                var expressionNull = Expression.Constant(null, propertyMap.DestinationPropertyType);
                transformedExpression =
                    Expression.Condition(Expression.NotEqual(result.ResolutionExpression, Expression.Constant(null)),
                        transformedExpression, expressionNull);
            }

            return Expression.Bind(propertyMap.DestinationProperty, transformedExpression);
        }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:19,代码来源:MappedTypeExpressionBinder.cs

示例13: CanGetExpressionResolutionResult

 public bool CanGetExpressionResolutionResult(ExpressionResolutionResult expressionResolutionResult, IValueResolver valueResolver)
 {
     return valueResolver is IMemberGetter;
 }
开发者ID:dennyli,项目名称:HandySolution,代码行数:4,代码来源:MemberGetterExpressionResultConverter.cs

示例14: BindCustomProjectionExpression

 private static MemberAssignment BindCustomProjectionExpression(PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionResolutionResult result)
 {
     return Expression.Bind(propertyMap.DestinationProperty, propertyTypeMap.CustomProjection.ConvertReplaceParameters(result.ResolutionExpression));
 }
开发者ID:gentledepp,项目名称:AutoMapper,代码行数:4,代码来源:CustomProjectionExpressionBinder.cs

示例15: IsMatch

 public bool IsMatch(PropertyMap propertyMap, TypeMap propertyTypeMap, ExpressionResolutionResult result)
 {
     return PrimitiveExtensions.IsNullableType(propertyMap.DestinationPropertyType)
            && !PrimitiveExtensions.IsNullableType(result.Type);
 }
开发者ID:CyranoChen,项目名称:Arsenalcn,代码行数:5,代码来源:NullableExpressionBinder.cs


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