• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# AutoMapper.TypeMap类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: CreateTypeMap

        public TypeMap CreateTypeMap(Type sourceType, Type destinationType, ProfileMap options, MemberList memberList)
        {
            var sourceTypeInfo = options.CreateTypeDetails(sourceType);
            var destTypeInfo = options.CreateTypeDetails(destinationType);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, memberList, options);

            foreach (var destProperty in destTypeInfo.PublicWriteAccessors)
            {
                var resolvers = new LinkedList<MemberInfo>();

                if (MapDestinationPropertyToSource(options, sourceTypeInfo, destProperty.DeclaringType, destProperty.GetMemberType(), destProperty.Name, resolvers))
                {
                    typeMap.AddPropertyMap(destProperty, resolvers);
                }
            }
            if (!destinationType.IsAbstract() && destinationType.IsClass())
            {
                foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length))
                {
                    if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
                    {
                        break;
                    }
                }
            }
            return typeMap;
        }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:28,代码来源:TypeMapFactory.cs


示例2: MapDestinationCtorToSource

        private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo, IProfileConfiguration options)
        {
            var parameters = new List<ConstructorParameterMap>();
            var ctorParameters = destCtor.GetParameters();

            if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
                return false;

            foreach (var parameter in ctorParameters)
            {
                var resolvers = new LinkedList<IValueResolver>();

                var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, parameter.GetType(), parameter.Name, resolvers);
                if(!canResolve && parameter.HasDefaultValue)
                {
                    canResolve = true;
                }

                var param = new ConstructorParameterMap(parameter, resolvers.ToArray(), canResolve);

                parameters.Add(param);
            }

            typeMap.AddConstructorMap(destCtor, parameters);

            return true;
        }
开发者ID:garora,项目名称:AutoMapper,代码行数:27,代码来源:TypeMapFactory.cs


示例3: CreateTypeMap

        public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IProfileConfiguration options, MemberList memberList)
        {
            var sourceTypeInfo = GetTypeInfo(sourceType, options);
            var destTypeInfo = GetTypeInfo(destinationType, options);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, memberList, options.ProfileName);

            foreach (var destProperty in destTypeInfo.PublicWriteAccessors)
            {
                var resolvers = new LinkedList<IValueResolver>();

                if (MapDestinationPropertyToSource(options, sourceTypeInfo, destProperty.GetMemberType(), destProperty.Name, resolvers))
                {
                    var destPropertyAccessor = destProperty.ToMemberAccessor();

                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers);
                }
            }
            if (!destinationType.IsAbstract() && destinationType.IsClass())
            {
                foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length))
                {
                    if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
                    {
                        break;
                    }
                }
            }
            return typeMap;
        }
开发者ID:garora,项目名称:AutoMapper,代码行数:30,代码来源:TypeMapFactory.cs


示例4: CreateTypeMap

        public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options)
        {
            var sourceTypeInfo = GetTypeInfo(sourceType);
            var destTypeInfo = GetTypeInfo(destinationType);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo);

            foreach (var destProperty in destTypeInfo.GetPublicWriteAccessors())
            {
                var members = new LinkedList<MemberInfo>();

                if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
                {
                    var resolvers = members.Select(mi => mi.ToMemberGetter());
                    var destPropertyAccessor = destProperty.ToMemberAccessor();
            #if !SILVERLIGHT
                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers);
            #else
                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers.Cast<IValueResolver>());
            #endif
                }
            }
            if (!destinationType.IsAbstract && destinationType.IsClass)
            {
                foreach (var destCtor in destTypeInfo.GetConstructors().OrderByDescending(ci => ci.GetParameters().Length))
                {
                    if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
                    {
                        break;
                    }
                }
            }
            return typeMap;
        }
开发者ID:patuww,项目名称:Automapper,代码行数:34,代码来源:TypeMapFactory.cs


示例5: MapDestinationCtorToSource

        private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeDetails sourceTypeInfo, ProfileMap options)
        {
            var ctorParameters = destCtor.GetParameters();

            if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
                return false;

            var ctorMap = new ConstructorMap(destCtor, typeMap);

            foreach (var parameter in ctorParameters)
            {
                var resolvers = new LinkedList<MemberInfo>();

                var canResolve = MapDestinationPropertyToSource(options, sourceTypeInfo, destCtor.DeclaringType, parameter.GetType(), parameter.Name, resolvers);
                if(!canResolve && parameter.HasDefaultValue)
                {
                    canResolve = true;
                }

                ctorMap.AddParameter(parameter, resolvers.ToArray(), canResolve);
            }

            typeMap.ConstructorMap = ctorMap;

            return true;
        }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:26,代码来源:TypeMapFactory.cs


示例6: AutoMapperConfigurationException

        public AutoMapperConfigurationException(TypeMap typeMap, string[] unmappedPropertyNames)
            : base(string.Format(
					"The following {3} properties on {0} are not mapped: \n\t{2}\nAdd a custom mapping expression, ignore, or rename the property on {1}.",
					typeMap.DestinationType.FullName, typeMap.SourceType.FullName, string.Join("\n\t", unmappedPropertyNames),
					unmappedPropertyNames.Length))
        {
        }
开发者ID:JonKruger,项目名称:AutoMapper,代码行数:7,代码来源:AutoMapperConfigurationException.cs


示例7: CreateTypeMap

        public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options,
            MemberList memberList)
        {
            var sourceTypeInfo = GetTypeInfo(sourceType, options);
            var destTypeInfo = GetTypeInfo(destinationType, options.ShouldMapProperty, options.ShouldMapField, new MethodInfo[0]);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo, memberList);

            foreach (var destProperty in destTypeInfo.PublicWriteAccessors)
            {
                var members = new LinkedList<MemberInfo>();

                if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
                {
                    var resolvers = members.Select(mi => mi.ToMemberGetter());
                    var destPropertyAccessor = destProperty.ToMemberAccessor();

                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers.Cast<IValueResolver>());
                }
            }
            if (!destinationType.IsAbstract() && destinationType.IsClass())
            {
                foreach (var destCtor in destTypeInfo.Constructors.OrderByDescending(ci => ci.GetParameters().Length))
                {
                    if (MapDestinationCtorToSource(typeMap, destCtor, sourceTypeInfo, options))
                    {
                        break;
                    }
                }
            }
            return typeMap;
        }
开发者ID:redwyre,项目名称:AutoMapper,代码行数:32,代码来源:TypeMapFactory.cs


示例8: MapDestinationCtorToSource

        private bool MapDestinationCtorToSource(TypeMap typeMap, ConstructorInfo destCtor, TypeInfo sourceTypeInfo,
                                                IMappingOptions options)
        {
            var parameters = new List<ConstructorParameterMap>();
            var ctorParameters = destCtor.GetParameters();

            if (ctorParameters.Length == 0 || !options.ConstructorMappingEnabled)
                return false;

            foreach (var parameter in ctorParameters)
            {
                var members = new LinkedList<MemberInfo>();

                if (!MapDestinationPropertyToSource(members, sourceTypeInfo, parameter.Name, options))
                    return false;

                var resolvers = members.Select(mi => mi.ToMemberGetter());

                var param = new ConstructorParameterMap(parameter, resolvers.ToArray());

                parameters.Add(param);
            }

            typeMap.AddConstructorMap(destCtor, parameters);

            return true;
        }
开发者ID:EdsonF,项目名称:AutoMapper,代码行数:27,代码来源:TypeMapFactory.cs


示例9: DryRunTypeMap

 private void DryRunTypeMap(ICollection<TypeMap> typeMapsChecked, TypePair types, TypeMap typeMap, ResolutionContext context)
 {
     if (typeMap != null)
     {
         typeMapsChecked.Add(typeMap);
         if(typeMap.CustomMapper != null || typeMap.TypeConverterType != null)
         {
             return;
         }
         CheckPropertyMaps(typeMapsChecked, typeMap, context);
     }
     else
     {
         var mapperToUse = _config.GetMappers().FirstOrDefault(mapper => mapper.IsMatch(types));
         if (mapperToUse == null && types.SourceType.IsNullableType())
         {
             var nullableTypes = new TypePair(Nullable.GetUnderlyingType(types.SourceType),
                 types.DestinationType);
             mapperToUse = _config.GetMappers().FirstOrDefault(mapper => mapper.IsMatch(nullableTypes));
         }
         if (mapperToUse == null)
         {
             throw new AutoMapperConfigurationException(types);
         }
         if (mapperToUse is ArrayMapper || mapperToUse is EnumerableMapper || mapperToUse is CollectionMapper)
         {
             CheckElementMaps(typeMapsChecked, types, context);
         }
     }
 }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:30,代码来源:ConfigurationValidator.cs


示例10: X

 public static IEnumerable<MapVisual> X(TypeMap map)
 {
     foreach (var propertyMap in map.GetPropertyMaps())
     {
         yield return new MapVisual
         {
             SourceSystem = extractSystem(propertyMap.SourceMember),
             SourceValue = getValue(propertyMap.SourceMember),
             TargetSystem = extractSystem(propertyMap.DestinationProperty),
             TargetValue = propertyMap.DestinationProperty.Name
         };
     }
 }
开发者ID:InfiniteComputingSystems,项目名称:Test,代码行数:13,代码来源:VisualizeMappings.cs


示例11: CreateTypeMap

        public TypeMap CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options)
        {
            var sourceTypeInfo = GetTypeInfo(sourceType);
            var destTypeInfo = GetTypeInfo(destinationType);

            var typeMap = new TypeMap(sourceTypeInfo, destTypeInfo);

            foreach (var destProperty in destTypeInfo.GetPublicWriteAccessors())
            {
                var members = new LinkedList<MemberInfo>();

                if (MapDestinationPropertyToSource(members, sourceTypeInfo, destProperty.Name, options))
                {
                    var resolvers = members.Select(mi => mi.ToMemberGetter()).Cast<IValueResolver>();
                    var destPropertyAccessor = destProperty.ToMemberAccessor();
                    typeMap.AddPropertyMap(destPropertyAccessor, resolvers);
                }
            }
            return typeMap;
        }
开发者ID:JonKruger,项目名称:AutoMapper,代码行数:20,代码来源:TypeMapFactory.cs


示例12: AutoMapperMappingException

 public AutoMapperMappingException(string message, Exception innerException, TypePair types, TypeMap typeMap, PropertyMap propertyMap)
     : this(message, innerException, types, typeMap)
 {
     PropertyMap = propertyMap;
 }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:5,代码来源:AutoMapperMappingException.cs


示例13: TypeMapConfigErrors

 public TypeMapConfigErrors(TypeMap typeMap, string[] unmappedPropertyNames)
 {
     TypeMap = typeMap;
     UnmappedPropertyNames = unmappedPropertyNames;
 }
开发者ID:suizhikuo,项目名称:SourceCollection,代码行数:5,代码来源:AutoMapperConfigurationException.cs


示例14: InheritTypes

 public void InheritTypes(TypeMap inheritedTypeMap)
 {
     foreach (var includedDerivedType in inheritedTypeMap._includedDerivedTypes
         .Where(includedDerivedType => !_includedDerivedTypes.Contains(includedDerivedType)))
     {
         _includedDerivedTypes.Add(includedDerivedType);
     }
 }
开发者ID:rasch1,项目名称:AutoMapper,代码行数:8,代码来源:TypeMap.cs


示例15: RegisterTypeMap

 public void RegisterTypeMap(TypeMap typeMap) => _typeMaps[typeMap.Types] = typeMap;
开发者ID:RahmanM,项目名称:AutoMapper,代码行数:1,代码来源:TypeMapRegistry.cs


示例16: ApplyDerivedMaps

 private void ApplyDerivedMaps(TypeMapRegistry typeMapRegistry, TypeMap baseMap, TypeMap typeMap)
 {
     foreach (var inheritedTypeMap in typeMap.IncludedDerivedTypes.Select(typeMapRegistry.GetTypeMap).Where(map => map != null))
     {
         inheritedTypeMap.ApplyInheritedMap(baseMap);
         ApplyDerivedMaps(typeMapRegistry, baseMap, inheritedTypeMap);
     }
 }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:8,代码来源:ProfileMap.cs


示例17: ConstructorMap

 public ConstructorMap(ConstructorInfo ctor, TypeMap typeMap)
 {
     Ctor = ctor;
     TypeMap = typeMap;
 }
开发者ID:sh-sabooni,项目名称:AutoMapper,代码行数:5,代码来源:ConstructorMap.cs


示例18: ApplyBaseMaps

 private static void ApplyBaseMaps(TypeMapRegistry typeMapRegistry, TypeMap derivedMap, TypeMap currentMap)
 {
     foreach (var baseMap in currentMap.IncludedBaseTypes.Select(typeMapRegistry.GetTypeMap).Where(baseMap => baseMap != null))
     {
         baseMap.IncludeDerivedTypes(currentMap.SourceType, currentMap.DestinationType);
         derivedMap.ApplyInheritedMap(baseMap);
         ApplyBaseMaps(typeMapRegistry, derivedMap, baseMap);
     }
 }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:9,代码来源:ProfileMap.cs


示例19: Configure

        private void Configure(TypeMapRegistry typeMapRegistry, TypeMap typeMap)
        {
            foreach (var action in AllTypeMapActions)
            {
                var expression = new MappingExpression(typeMap.Types, typeMap.ConfiguredMemberList);

                action(typeMap, expression);

                expression.Configure(typeMap);
            }

            foreach (var action in AllPropertyMapActions)
            {
                foreach (var propertyMap in typeMap.GetPropertyMaps())
                {
                    var memberExpression = new MappingExpression.MemberConfigurationExpression(propertyMap.DestinationProperty, typeMap.SourceType);

                    action(propertyMap, memberExpression);

                    memberExpression.Configure(typeMap);
                }
            }

            ApplyBaseMaps(typeMapRegistry, typeMap, typeMap);
            ApplyDerivedMaps(typeMapRegistry, typeMap, typeMap);
        }
开发者ID:GeertVL,项目名称:AutoMapper,代码行数:26,代码来源:ProfileMap.cs


示例20: ApplyInheritedTypeMap

        private void ApplyInheritedTypeMap(TypeMap inheritedTypeMap)
        {
            foreach (var inheritedMappedProperty in inheritedTypeMap.GetPropertyMaps().Where(m => m.IsMapped()))
            {
                var conventionPropertyMap = GetPropertyMaps()
                    .SingleOrDefault(m =>
                        m.DestinationProperty.Name == inheritedMappedProperty.DestinationProperty.Name);

                if (conventionPropertyMap != null)
                {
                    conventionPropertyMap.ApplyInheritedPropertyMap(inheritedMappedProperty);
                }
                else
                {
                    var propertyMap = new PropertyMap(inheritedMappedProperty, this);

                    _inheritedMaps.Add(propertyMap);
                }
            }

            //Include BeforeMap
            foreach (var beforeMapAction in inheritedTypeMap._beforeMapActions)
            {
                AddBeforeMapAction(beforeMapAction);
            }
            //Include AfterMap
            foreach (var afterMapAction in inheritedTypeMap._afterMapActions)
            {
                AddAfterMapAction(afterMapAction);
            }
        }
开发者ID:jbogard,项目名称:AutoMapper,代码行数:31,代码来源:TypeMap.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ClientModel.ServiceClient类代码示例发布时间:2022-05-24
下一篇:
C# AutoMapper.ResolutionContext类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap