Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapper 遇到未注册过的Type时,会initMaps,但原有类型会丢失CustomMapper #41

Closed
kaanid opened this issue Nov 8, 2018 · 4 comments

Comments

@kaanid
Copy link

kaanid commented Nov 8, 2018

initMaps,但原有类型会丢失,自定义设置CustomMapper
item.CustomMapper!=null
重新init
item.CustomMapper==null

@UtilCore
Copy link
Contributor

请提供代码示例让我重现BUG

@kaanid
Copy link
Author

kaanid commented Nov 14, 2018

代码在这里,https://github.com/kaanid/custommapper
请看一下。谢谢

@UtilCore
Copy link
Contributor

已解决,下面是修改的部分,已推送Nuget
/// <summary> /// 初始化映射配置 /// </summary> private static void InitMaps( Type sourceType, Type destinationType ) { try { var maps = Mapper.Configuration.GetAllTypeMaps(); ClearConfig(); Mapper.Initialize( config => { config.CreateMap( sourceType, destinationType ); } ); foreach( var map in maps ) Mapper.Configuration.RegisterTypeMap( map ); } catch( InvalidOperationException ) { Mapper.Initialize( config => { config.CreateMap( sourceType, destinationType ); } ); } }

@kaanid
Copy link
Author

kaanid commented Nov 20, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants