When I read the book 'ASP_NET-MVC-5-with-Bootstrap-and-Knockout_js', the blew code can't be compiled
AutoMapper.Mapper.CreateMap(_sourceType, _destinationType);
If I modify it Mapper.Initialize(cfg => cfg.CreateMap<_sourceType, _destinationType>()),according the new version guide,then got this error:Severity Code Description Project File Line Suppression State Error CS0246 The type or namespace name '_sourceType' could not be found (are you missing a using directive or an assembly reference?) Can anyone help me give some advice?
namespace BootstrapIntroduction.Filters {
[AttributeUsage(AttributeTargets.Method)]
public class GenerateResultListFilterAttribute : FilterAttribute, IResultFilter {
private readonly Type _sourceType;
private readonly Type _destinationType;
public GenerateResultListFilterAttribute(Type sourceType, Type destinationType) {
_sourceType = sourceType;
_destinationType = destinationType;
}
public void OnResultExecuting(ResultExecutingContext filterContext) {
var model = filterContext.Controller.ViewData.Model;
var resultListGenericType = typeof(ResultList<>).MakeGenericType(new Type[] { _destinationType });
var srcGenericType = typeof(List<>).MakeGenericType(new Type[] { _sourceType });
var destGenericType = typeof(List<>).MakeGenericType(new Type[] { _destinationType });
AutoMapper.Mapper.CreateMap(_sourceType, _destinationType);
var viewModel = AutoMapper.Mapper.Map(model, srcGenericType, destGenericType);
var queryOptions = filterContext.Controller.ViewData.ContainsKey("QueryOptions") ?
filterContext.Controller.ViewData["QueryOptions"] : new QueryOptions();
var resultList = Activator.CreateInstance(resultListGenericType, viewModel, queryOptions);
filterContext.Controller.ViewData.Model = resultList;
}
public void OnResultExecuted(ResultExecutedContext filterContext) {
}
}
I found someone also had the same question but no answer:http://www.endyourif.com/integrating-automapper-with-an-mvc-result-filter/