我试图利用<代码>Automapper绘制这些特性的地图。
public class SourceClass
{
public object emailNotification { get; set; }
}
public class DestinationClass
{
public int emailNotificationId { get; set; }
public string emailNotificationLookupName { get; set; }
}
当I debug it时,email Notification
= ValueKind = 反对: “{“id”:3,“lookupName”:“Send Email inform”}"
。
预期成果
- emailNotificationId = 3
- emailNotificationLookupName = "Send Email Notification"
这是我目前的制图代码,但我有这一汇编错误:。
public class SourceProfile : AutoMapper.Profile
{
public SourceProfile()
{
CreateMap<SourceClass, DestinationClass>()
.ForMember(dest => dest.emailNotificationId, opt => opt.MapFrom(src =>
src.emailNotification != null && src.emailNotification is JObject jObject ? jObject["id"].Value<int>() : 0))
.ForMember(dest => dest.emailNotificationLookupName, opt => opt.MapFrom(src =>
src.emailNotification != null && src.emailNotification is JObject jObject ? jObject["lookupName"].Value<string>() : null))
;
}
}
在尝试了永道的两种解决办法之后,我可以毫不错误地汇编,但我仍然无法绘制出价值图。