c# - Automapper custom object -
how have configure automapper map this:
class source { guid id; double price; }
to this:
class destination { guid id; destinationdifference difference; } class destinationdifference { decimal amount; }
first: should read faqs on how post question , information should added. (no, i'm not downvoter)
here example how mapping work. please note, i've changed classes bit, because automapper needs properties.
source source = new source(); source.id = guid.newguid(); source.price = 10.0; mapper.initialize(x => x.createmap<source, destination>() .formember(a => a.difference, b => b.mapfrom(s => new destinationdifference() { amount = (decimal)s.price }))); destination destination = mapper.map<source, destination>(source);
classes:
class source { public guid id { get; set; } public double price { get; set; } } class destination { public guid id { get; set; } public destinationdifference difference { get; set; } } class destinationdifference { public decimal amount { get; set; } }
Comments
Post a Comment