سؤال

I'm using two WCF services that declare a class Donkey each. Those Donkey classes, although identical in structure, aren't the same type, due to namespace issues.

This far I'm using using (as described f.i. here), but I feel that I'd like to get it under some more strict control.

Any suggestions on how (and where) to place a data contract converter that maps the both Donkey classes to each other? I know that it's a bit goofy question. It's got to do with the fact that I'm not sure if that's even possible. Feel free to correct my formulation.

All suggestions are welcome. I'm considering writing my own data definition layer and create my own, better Donkey objects (with booze and hookers, if one dares to use a reference to Futurama's Bender).

هل كانت مفيدة؟

المحلول

If I understand your situation correctly, you have two identical structures of different types that you want to use interchangeably. In this case, all you need is to define implicit casts. So, in one definition of Donkey, define a cast to and from the other Donkey.

If you do not have control over the two Donkeys or you would prefer to keep the classes decoupled, then adding a third Donkey class would make more sense. In this class, you would define the casts from the other Donkeys.

Depending on the details of your situation, you should try to use just one of the Donkeys as much as you can throughout your project, and only use the other when necessary.

نصائح أخرى

Explicit namespaces will do the trick.

You can merge your Donkey classes, if they are in fact the same structurally, to another project which the two namespaces can reference.

If you have control over how these disparate Donkey classes are conceived you can allow them each to share an interface IDonkey but that's more or less the same syntactical solution to merging.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top