c# - Automapper pass ForMember(s) as argument -
is there way can this?
public void createmap<t, i>(??? formember) { mapper.createmap<t, i>().formember(formember); }
i'm trying pass formember argument method can attach map.
here possible way it: given 2 classes
internal class exampleclass { public string name { get; set; } } internal class otherexampleclass { public string othername { get; set; } }
define following function
private static void createmap<from, to> (expression<func<from, object>> fromexpression, expression<func<to, object>> toexpression) { mapper.createmap<from, to>() .formember(toexpression, opt => opt.mapfrom(fromexpression)); }
and call passing lambdas directly:
createmap<exampleclass, otherexampleclass>(fromclass => fromclass.name, toclass => toclass.othername);
the imappingexpression
(the type returned formember
method) not should use. holds configuration , chaining methods don't think supposed come outside. brief survey of code couldn't find point @ add imappingexpression
using 2 lambdas best bet imo
Comments
Post a Comment