如何解决AutoMapper-使用属性属性进行自定义类型转换
我正在尝试确定是否可以将自定义类型转换用于使用可用属性(例如ValueConverterAttribute)的映射。例如...
public class Source
{
public string Value1 { get; set; }
}
[AutoMap(typeof(Source),Reverse = true)]
public class Destination
{
[?? ValueCoverter ??]
public CustomType Value1 { get; set; }
}
public class CustomType
{
private string _someValue { get; set; }
// Constructor
public CustomType(string someValue)
{
_someValue = someValue;
}
// Do some stuff with _someValue ...
}
...然后在我的Mapper配置中...
var config = new MapperConfiguration(cfg =>
{
cfg.AddMaps(typeof(Destination));
});
var mapper = config.CreateMapper();
Source source = new Source()
{
Value1 = "Some value"
};
Destination destination = mapper.Map<Destination>(source);
我的问题是,我可以使用[ValueConverter]
属性在 Destination.Value1 属性上应用自定义类型转换器吗?我似乎找不到使用ValueConverter属性的任何示例。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。