自动映射程序 IValue解析器引发错误 类型不能用作泛型类型或方法中的类型参数'TValueResolver'



我尝试在新版AutoMapper中实现IValueResolver接口。我已经实现了ResourceTypeResolver类,如下所示。。

public interface IValueResolver<in TSource, in TDestination, TDestMember>
{
TDestMember Resolve(TSource source, TDestination destination, TDestMember destMember, ResolutionContext context);
}
public class ResourceTypeResolver : IValueResolver<PMEasy.Model.Entity.Resource, PMEasy.Web.Models.Gantt.GanttResource, string>
{
private ILookupService LookupService;
public ResourceTypeResolver(ILookupService lookupService)
{
LookupService = lookupService;
}
public string Resolve(PMEasy.Model.Entity.Resource source, PMEasy.Web.Models.Gantt.GanttResource destination, string member, ResolutionContext context)
{
if (source.Type.HasValue && source.Type != Guid.Empty)
{
var resourceType = LookupService.GetLookupListByName("ResourceType").Where(con => con.GUID == source.Type.Value).FirstOrDefault();
return resourceType != null ? resourceType.Value : string.Empty;
}
else return "Work";
}
}

在映射器配置中使用此ResourceTypeResolver之后

var config = new MapperConfiguration(cfg =>
{
cfg.CreateMap<Resource, GanttResource>()
.ForMember(dst => dst.TypeName, opt => opt.ResolveUsing<ResourceTypeResolver>()));
} 

这里我在ResolveUsing上下文中得到一个错误,

错误19类型"PMEasy.Web.AutoMapper.ResourceTypeResolver"不能用作泛型类型或方法"AutoMapper.IMemberConfigurationExpression.ResolveUsing()"中的类型参数"TValueResolver"。没有从"PMEay.Web.AutoMapper.ResultypeResolver"到"AutoMappers.IValueResolver"的隐式引用转换。D: \PEasy\Development\PEasyDev\PEasy.Web\App_Start\AutoMapperConfig.cs 58 59 PMEasy.Web

有什么想法可以解决这个问题吗?

您似乎创建了自己的接口IValueResolver<in TSource, in TDestination, TDestMember>,而不是使用automapper的接口。Soo,删除你的接口定义。

相关内容

  • 没有找到相关文章

最新更新