How to perform deep copy in this case?

I saw an interesting article a guy wrote on how to create a deep copy of a generic object.

http://www.codeproject.com/useritems/0g_GenericsAndCloning.asp

It's not perfect.. as some of the comments say, but would work well for what I'm doing except I cannot do this because I do not believe the CF supports that type of serialization.

Here's what I have.. (specific class structure shown below)

Class A - base class
Class B : Class A
ClassB1 : ClassB
ClassB2:ClassB
Class C : Class A
ClassC2:ClassC
ClassC3:ClassC
//possibly others

Now.. I need a way to perform a deep copy on all of the final classes. Would be nice to have it in the parent class and could do it in some general way..

Or.. do I have to write a sperate clone method in each where I create a new object of the same type and copy over the data manually

More specifically my classes have this type of information

DataFormat
FontFormat : DataFormat
OutlinedFont : FontFormat
BitmapFont : FontFomart
BarcodeFormat : DataFormat
Code39 : BarcodeFormat
Interleave2of5 : BarcodeFormat

Basically I'm writing a library for an old barcode printer. I want to be able to create a "TagFormat" and add these formatting objects (which contain position and formatting information)  to collection in it.. then the format will call CreateTag which should return a Tag with the formatting information with it (The formats will have no value for what to print yet). Then I need to actually fill in the String values for the formats without affecting the original format itself. The tag itself hides the formatting information from the user, it just allows for the fields to be filled, but the printer itself needs that infomation so it needs to be deep copied so that changing 1 tag doesn't affect all.

Question is.. what is the best way to do it in this case


Answer this question

How to perform deep copy in this case?

  • Anonymous Hacker

    Depending upon how important performance is there are several types of serialization methods you could use to do this. Reflection could also do this but i think at a bigger penalty

  • MonicaMaloney

    I found a better way to organize my classes so that the formats are actually contained in a field class. The fields are automatically created when the tag itself is created and can be changed without affecting the reference to the format. So look like I will not need a deep copy.

    However.. if anyone wants to post a good example of how to do it feel free.

  • How to perform deep copy in this case?