我有一个创建从数组映射到对象类型的问题。所以任何人都有这个答案,那么请帮助我。Automapper:阵列到对象映射
视图模型(来源类):
public class HealthView : IView
{
public Guid Id { get; set; }
public string Type { get; set; }
public string Value { get; set; }
[JsonIgnore]
public DateTime? HealthCheckDateTime { get; set; }
public string HealthCheckDateTimeString { get { return HealthCheckDateTime.GetValueOrDefault().ToString(CultureInfo.InvariantCulture); } }
}
在此(目标类)转化:
public class HealthResponse : WebApiResonseBase
{
public HealthResponse()
{
Value = new HealthLine[0];
}
public HealthLine[] Value { get; set; }
public class HealthLine
{
public Guid Id { get; set; }
public string Type { get; set; }
public string Value { get; set; }
public DateTime? HealthCheckDateTime { get; set; }
public string HealthCheckDateTimeString { get; set; }
}
}
映射:
CreateMap<HealthView[], HealthResponse>()
.ForMember(x => x.RedirectRequired, o => o.Ignore())
.ForMember(x => x.Uri, o => o.Ignore());
这是我的整个过程中,我尝试以不同的方式,但我得到了错误。
你到底想达到什么目的? –
我已经解决了这个问题。但是我的身边出现了一些问题。所以我会在稍后给出答案。 –
我正在尝试数组映射到使用automapper的对象成员映射.. –