So I started using AutoMapper for my ASP.NET MVC project, looked at a couple of examples and wrote my first IValueFormatter implementation when a blue wiggly popped up for IValueFormatter: Interface 'AutoMapper.IValueFormatter' is obsolete: "Formatters should not not be used". Well, okay, then how am I supposed to e.g. convert a DateTime to, say, a string?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Just create mapping for the property without using IValueFormatter. For example:
Mapper.CreateMap<DbItem, ItemView>()
.ForMember(item => item.DateCreated, opt => opt.ResolveUsing(i => {
var date = i.DateCreated;
return date.ToShortDateString();
}));
Instead of :
Mapper.CreateMap<DbItem, ItemView>().ForMember(item => item.DateCreated,
item => item.AddFormatter<ItemDateCreatedFormater>());