AutoMapper - setting destination string to null actually makes it string.Empty

牧云@^-^@ 提交于 2019-12-06 00:04:16

I found the setting after looking through the source code... Confirming that this is not a bug, but in fact a configurable setting.

When I configure my mappings..

Mapper.Initialize(x =>
{
    x.AddProfile<UIProfile>();
    x.AddProfile<InfrastructureProfile>();
    x.AllowNullDestinationValues = true; // does exactly what it says (false by default)
});

you could define map for strings using

ITypeConverter<string, string>

and when you convert return null if null. I think it is by design that you get an empty string and I even find this natural and useful myself but I may of course be wrong ;)

I can provide more precise code than above upon request but reckon you know what you're doing.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!