Last active
May 20, 2019 08:48
-
-
Save greendimka/4fa78aeb37938f46343cfd3e4cc1f028 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var config = new MapperConfiguration(c => | |
{ | |
c.CreateMap<SourceClass, TargetClass>() | |
.ForMember(x => x.Vals, o => o.MapFrom((srcCls, trgCls) => | |
{ | |
trgCls.Vals.Clear(); | |
trgCls.Vals.AddRange(srcCls.Vals); | |
return trgCls.Vals; | |
})); | |
}); | |
config.AssertConfigurationIsValid(); | |
IMapper mapper = new Mapper(config); | |
var src = new SourceClass(); | |
var trg = mapper.Map<TargetClass>(src); | |
Console.WriteLine(string.Join('|', trg.Vals)); | |
} | |
} | |
class SourceClass | |
{ | |
public SourceClass() | |
{ | |
Vals = new List<int> { 1, 2, 3 }; | |
} | |
public List<int> Vals { get; set; } | |
} | |
class TargetClass | |
{ | |
private List<int> _vals = new List<int>(); | |
public List<int> Vals => _vals; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment