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


C# IConfigurationProvider.GetMappers方法代码示例

本文整理汇总了C#中IConfigurationProvider.GetMappers方法的典型用法代码示例。如果您正苦于以下问题:C# IConfigurationProvider.GetMappers方法的具体用法?C# IConfigurationProvider.GetMappers怎么用?C# IConfigurationProvider.GetMappers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IConfigurationProvider的用法示例。


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

示例1: CreatePropertyMapFunc

        private static Expression CreatePropertyMapFunc(
            PropertyMap propertyMap,
            IConfigurationProvider configurationProvider,
            TypeMapRegistry typeMapRegistry,
            ParameterExpression srcParam,
            ParameterExpression destParam,
            ParameterExpression ctxtParam,
            ref ParameterExpression propertyContext)
        {
            var valueResolverExpr = BuildValueResolverFunc(propertyMap, typeMapRegistry, srcParam, ctxtParam);
            var destMember = MakeMemberAccess(destParam, propertyMap.DestinationProperty.MemberInfo);

            Expression getter;

            var pi = propertyMap.DestinationProperty.MemberInfo as PropertyInfo;
            if (pi != null && pi.GetGetMethod(true) == null)
            {
                getter = Default(propertyMap.DestinationPropertyType);
            }
            else
            {
                getter = destMember;
            }

            var destValueExpr = propertyMap.UseDestinationValue
                ? getter
                : Default(propertyMap.TypeMap.DestinationType);

            if (propertyMap.SourceType != null && propertyMap.DestinationPropertyType != null)
            {
                var typePair = new TypePair(propertyMap.SourceType, propertyMap.DestinationPropertyType);
                var typeMap = typeMapRegistry.GetTypeMap(typePair);
                if (typeMap != null && (typeMap.TypeConverterType != null || typeMap.CustomMapper != null))
                {
                    if(!typeMap.Sealed)
                        typeMap.Seal(typeMapRegistry, configurationProvider);
                    valueResolverExpr = typeMap.MapExpression.ReplaceParameters(valueResolverExpr, destValueExpr, ctxtParam);
                }
                else
                {
                    var match = configurationProvider.GetMappers().FirstOrDefault(m => m.IsMatch(typePair));
                    var expressionMapper = match as IObjectMapExpression;
                    if (expressionMapper != null)
                        valueResolverExpr = expressionMapper.MapExpression(valueResolverExpr, destValueExpr,
                            ctxtParam);
                    else
                        valueResolverExpr = SetMap(propertyMap, valueResolverExpr, destValueExpr, ref propertyContext);
                }
            }
            else
            {
                valueResolverExpr = SetMap(propertyMap, valueResolverExpr, destValueExpr, ref propertyContext);
            }

            if (propertyMap.Condition != null)
            {
                valueResolverExpr =
                    Condition(
                        Invoke(
                            propertyMap.Condition,
                            srcParam,
                            destParam,
                            ToType(valueResolverExpr, propertyMap.Condition.Parameters[2].Type),
                            ToType(destValueExpr, propertyMap.Condition.Parameters[2].Type),
                            ctxtParam
                            ),
                        Convert(valueResolverExpr, propertyMap.DestinationPropertyType),
                        destValueExpr
                        );
            }

            Expression mapperExpr;
            if (propertyMap.DestinationProperty.MemberInfo is FieldInfo)
            {
                mapperExpr = propertyMap.SourceType != propertyMap.DestinationPropertyType
                    ? Assign(destMember, Convert(valueResolverExpr, propertyMap.DestinationPropertyType))
                    : Assign(getter, valueResolverExpr);
            }
            else
            {
                var setter = ((PropertyInfo) propertyMap.DestinationProperty.MemberInfo).GetSetMethod(true);
                if (setter == null)
                {
                    mapperExpr = valueResolverExpr;
                }
                else
                {
                    mapperExpr = Assign(destMember, propertyMap.SourceType != propertyMap.DestinationPropertyType
                        ? Convert(valueResolverExpr, propertyMap.DestinationPropertyType)
                        : valueResolverExpr);
                }
            }

            if (propertyMap.PreCondition != null)
            {
                mapperExpr = IfThen(
                    Invoke(propertyMap.PreCondition, srcParam, ctxtParam),
                    mapperExpr
                    );
            }
//.........这里部分代码省略.........
开发者ID:sh-sabooni,项目名称:AutoMapper,代码行数:101,代码来源:TypeMapPlanBuilder.cs

示例2: MapExpression

 private static Expression MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider,
     PropertyMap propertyMap, Expression itemParam, Expression contextParam, TypePair typePair)
 {
     Expression itemExpr;
     var typeMap = configurationProvider.ResolveTypeMap(typePair);
     if (typeMap != null && (typeMap.TypeConverterType != null || typeMap.CustomMapper != null))
     {
         if (!typeMap.Sealed)
             typeMap.Seal(typeMapRegistry, configurationProvider);
         return typeMap.MapExpression.ReplaceParameters(itemParam, Default(typePair.DestinationType), contextParam);
     }
     var match = configurationProvider.GetMappers().FirstOrDefault(m => m.IsMatch(typePair));
     if (match != null && typeMap == null)
     {
         itemExpr =
             ToType(
                 match.MapExpression(typeMapRegistry, configurationProvider, propertyMap, itemParam,
                     Default(typePair.DestinationType), contextParam), typePair.DestinationType);
     }
     else
     {
         var mapMethod =
             typeof (ResolutionContext).GetDeclaredMethods()
                 .First(m => m.Name == "Map")
                 .MakeGenericMethod(typePair.SourceType, typePair.DestinationType);
         itemExpr = Call(contextParam, mapMethod, itemParam, Default(typePair.DestinationType));
     }
     return itemExpr;
 }
开发者ID:284247028,项目名称:AutoMapper,代码行数:29,代码来源:CollectionMapper.cs

示例3: MapExpression

 public static Expression MapExpression(TypeMapRegistry typeMapRegistry, IConfigurationProvider configurationProvider,
     TypePair typePair, Expression sourceParameter, Expression contextParameter, PropertyMap propertyMap = null, Expression destinationParameter = null)
 {
     if(destinationParameter == null)
     {
         destinationParameter = Default(typePair.DestinationType);
     }
     var typeMap = configurationProvider.ResolveTypeMap(typePair);
     if(typeMap != null)
     {
         if(!typeMap.HasDerivedTypesToInclude())
         {
             typeMap.Seal(typeMapRegistry, configurationProvider);
             if(typeMap.MapExpression != null)
             {
                 return typeMap.MapExpression.ConvertReplaceParameters(sourceParameter, destinationParameter, contextParameter);
             }
             else
             {
                 return ContextMap(typePair, sourceParameter, contextParameter, destinationParameter);
             }
         }
         else
         {
             return ContextMap(typePair, sourceParameter, contextParameter, destinationParameter);
         }
     }
     var match = configurationProvider.GetMappers().FirstOrDefault(m => m.IsMatch(typePair));
     if(match != null)
     {
         var mapperExpression = match.MapExpression(typeMapRegistry, configurationProvider, propertyMap, sourceParameter, destinationParameter, contextParameter);
         return ToType(mapperExpression, typePair.DestinationType);
     }
     return ContextMap(typePair, sourceParameter, contextParameter, destinationParameter);
 }
开发者ID:tlycken,项目名称:AutoMapper,代码行数:35,代码来源:TypeMapPlanBuilder.cs

示例4: CreatePropertyMapFunc

        private static Expression CreatePropertyMapFunc(
            PropertyMap propertyMap,
            IConfigurationProvider configurationProvider,
            TypeMapRegistry typeMapRegistry,
            ParameterExpression srcParam,
            ParameterExpression destParam,
            ParameterExpression ctxtParam)
        {
            var destMember = MakeMemberAccess(destParam, propertyMap.DestinationProperty);

            Expression getter;

            var pi = propertyMap.DestinationProperty as PropertyInfo;
            if (pi != null && pi.GetGetMethod(true) == null)
            {
                getter = Default(propertyMap.DestinationPropertyType);
            }
            else
            {
                getter = destMember;
            }

            var destValueExpr = propertyMap.UseDestinationValue
                ? getter
                : Default(propertyMap.DestinationPropertyType);

            var valueResolverExpr = BuildValueResolverFunc(propertyMap, typeMapRegistry, srcParam, destParam, getter, ctxtParam);

            if (propertyMap.DestinationPropertyType != null)
            {
                var typePair = new TypePair(valueResolverExpr.Type, propertyMap.DestinationPropertyType);
                var typeMap = configurationProvider.ResolveTypeMap(typePair);
                var match = configurationProvider.GetMappers().FirstOrDefault(m => m.IsMatch(typePair));
                if (typeMap != null && (typeMap.TypeConverterType != null || typeMap.CustomMapper != null))
                {
                    if(typeMap.Sealed != true)
                        typeMap.Seal(typeMapRegistry, configurationProvider);
                    valueResolverExpr = typeMap.MapExpression.ConvertReplaceParameters(valueResolverExpr, destValueExpr, ctxtParam);
                }
                else if (match != null && typeMap == null)
                {
                    valueResolverExpr = match.MapExpression(typeMapRegistry, configurationProvider,
                        propertyMap, valueResolverExpr, destValueExpr,
                        ctxtParam);
                }
                else
                {
                    valueResolverExpr = SetMap(propertyMap, valueResolverExpr, destValueExpr, ctxtParam);
                }
            }
            else
            {
                valueResolverExpr = SetMap(propertyMap, valueResolverExpr, destValueExpr, ctxtParam);
            }

            Expression mapperExpr;
            if (propertyMap.DestinationProperty is FieldInfo)
            {
                mapperExpr = propertyMap.SourceType != propertyMap.DestinationPropertyType
                    ? Assign(destMember, ToType(valueResolverExpr, propertyMap.DestinationPropertyType))
                    : Assign(getter, valueResolverExpr);
            }
            else
            {
                var setter = ((PropertyInfo) propertyMap.DestinationProperty).GetSetMethod(true);
                if (setter == null)
                {
                    mapperExpr = valueResolverExpr;
                }
                else
                {
                    mapperExpr = Assign(destMember, propertyMap.SourceType != propertyMap.DestinationPropertyType
                        ? ToType(valueResolverExpr, propertyMap.DestinationPropertyType)
                        : valueResolverExpr);
                }
            }

            if (propertyMap.PreCondition != null)
            {
                mapperExpr = IfThen(
                    propertyMap.PreCondition.ConvertReplaceParameters(srcParam, ctxtParam),
                    mapperExpr
                    );
            }
            if (propertyMap.Condition != null)
            {
                mapperExpr = IfThen(
                    propertyMap.Condition.ConvertReplaceParameters(
                        srcParam,
                        destParam,
                        ToType(valueResolverExpr, propertyMap.Condition.Parameters[2].Type),
                        ToType(getter, propertyMap.Condition.Parameters[2].Type),
                        ctxtParam
                        ),
                    mapperExpr
                    );
            }

            return mapperExpr;
        }
开发者ID:RahmanM,项目名称:AutoMapper,代码行数:100,代码来源:TypeMapPlanBuilder.cs


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