c# - Adding AutoMapper Type Mapping Conventions For Generic Types in WCF Contract -
i have wcf service uses generics in data contract, example (simplified):
public getdetails(statusfield<string> status);
now wcf supports generics creating non-generic equivalent type every possible value of t in generic. so, above example, client consuming wcf service see following signature above function:
public getdetails(stringstatusfield status); //...
now client has copy of generic version of statusfield class. want use automapper in client, map between generic statusfield , types generated above wcf (such stringstatusfield) can call service. manually creating maps @ client startup, so:
mapper.createmap<statusfield<string>, stringstatusfield>();
however laborious there 50+ possible values of wcf has converted. extending idea, use reflection automatically create maps types , solution using.
ideally see solution ties architecture of automapper avoid having reflection manually. conceptually, require way of defining convention automapper use allow tie 2 types together, similar how allows custom conventions specified when matching properties. yet, have not seen way , question answered here, if knows how can done, in relation above scenario.
btw aware may thinking of mapper.dynamicmap() solution problem. firstly, dont want use means debugging potentially harder (as indicated in other posts similar this) , if statusfield nested in object graph being passed wcf method, im not sure solution work , potentially lead type being incorrectly mapped , other such issues. concretely define allowable mappings if possible.
unsure if automapper provides support after, if did using reflection propose.
if opposed reflection solution due performance concerns (which should one-time startup cost), maybe t4 template-based code generation solution might worth considering?
Comments
Post a Comment