Generated Translators and Manually Translating

Topics: General Discussion Forum, July and December Releases Forum, Service Factory Modeling Edition Forum
Mar 18, 2008 at 4:35 PM
Can anyone please clarify something for me? With the translator classes generated in the Service Implementation, what is the best practice for the data members that require manual translation? For example, in a business entity class 'BEProduct' I have a member of type enum ProductType. Similarly in a data contract class 'DCProduct' I have a member of type enum ProdType. So I need to manually translate between these but if I modify the generated files I lose the changes next time they are generated. Would changing the generated classes to partial classes then adding the manual translating code to another non-generated file be wise? Or is moving the generated files out of the generated file folder be better? It seems either way I'd end up changing generated files and manually tweaking something, isn't there some design for these classes that would permit the manual translation code without touching the generated files??

Mar 18, 2008 at 7:23 PM
Any additional customization to the generated classes should be done (ideally) in a partial class outside the "CodeGeneration" folder. You can think of adding methods/properties to this class (your custom partial class).
Some further ideas

Mar 19, 2008 at 1:08 PM
So using partial classes to extend the generated classes will require changing the regenerated files each time to make the generated classes partial right? This is obviously a trivial task but is there a good reason why the code generator does not make these partial to begin with?

I am considering just now creating a separate "Service Adaptor" class in the Service Implementation project that would call the generated translator methods and also call another set of manually created methods that provide the additional translations required. Does this sound good or am I missing the point of a "Service Adaptor"?

Thanks for the help!
Mar 19, 2008 at 1:56 PM
The generated classes are always partial so you don't need to change the generated files. In case you still need to add further customization you can simple update the text template that drives the code generation and that's it.
Mar 19, 2008 at 2:30 PM
I know the other generated classes are but the classes generated by the "Create Translator" are definitely not partial, maybe this was just an oversight as opposed to there being some good reason behind it...? Anyway thanks for your help.