How to serialize a complete VERY LARGE class, all but, possibly, NOTone member, at will

  • Thread starter Thread starter pamela fluente
  • Start date Start date
P

pamela fluente

I have a class marked serialized. This class has some *thousands*
fields and properties.

Among them there is, in particular, 1 object. Let's call it MyObject.

What I need is being able, at my will, to perform either one of the
following actions:

- Serialize the class including MyObject
- Serialize the class EXCLUDING MyObject (that is, like if
MyObject would not be serializable)

1. I have already looked into ISerializable - of course - but at
first sight seemed impractical to use
because I have thousands properties and fields and clearly I cannot
write a ISerializable.GetObjectData
for all of them. Also it would not be easily maintainable.

2. I do not wish to wrap the other properties and fields in another
class, because that would be awkward.

How can I do that?

Thank you very much for any help.

-P
 
Hello.

Perhaps you can save MyObject, assign it to Nothing, serialize, and restore
MyObject ?

Gilbert
 
Hello.

Perhaps you can save MyObject, assign it to Nothing, serialize, and restore
MyObject ?

Gilbert

Thank you very much, very helpful idea.

That's seems a simple solution

-P
 
Just out of interest, why do you feel you need thousands of fields and
properties declared within one class?
 
Sometimes on groups you need to exaggerate a little to avoid people be
tempted to give you
answer that you may not be interested in.

Anyway if not thousand, I have worked with classes with so many
properties that
you certainly do not wish embark in the
ISerializable.GetObjectData :-)

Big projects here! :-)


-P
 
Even if you're talking hundreds, by the time any class got to that state I'd
be re-examining my design and looking to go to key/value attributes instead
of hard-coded properties.

With many hundreds of properties (or more) you're likely to cause yourself
other pains. I can't imagine IntelliSense liking it (nor the rest of VS for
that matter), future maintenance could be problematic, your code files would
likely end up getting rather large (and thus your compiled binary would as
well) and if every one of those properties has a backing-store variable
associated with it then your heap is going to be enormous with just a few
instances of that one class loaded up.

Cheers,
Alex





Sometimes on groups you need to exaggerate a little to avoid people be
tempted to give you
answer that you may not be interested in.

Anyway if not thousand, I have worked with classes with so many
properties that
you certainly do not wish embark in the
ISerializable.GetObjectData :-)

Big projects here! :-)


-P
 
Yes Alex, that's sounds very reasonable.

Modular design: that's the key to handle complexity !
 
Back
Top