Nested Serialization

  • Thread starter Thread starter Chuck Bowling
  • Start date Start date
C

Chuck Bowling

When you use the [Serializable] tag are nested classes also serialized?

If so, can you just use a [NonSerialized] tag to exclude them from the
stream?
 
Chuck,

If a class is nested, it only means that the class is defined within
another class. This is not serialized unless the parent class holds a
reference to an instance of the nested class.

If you want to prevent a field from being serialized, then you can place
the NonSerialized attribute on the field to keep it from being serialized.

Hope this helps.
 
Thanks Nicholas.

I would have tested it myself but figured somebody here would probably know
without going thru the trouble...

Nicholas Paldino said:
Chuck,

If a class is nested, it only means that the class is defined within
another class. This is not serialized unless the parent class holds a
reference to an instance of the nested class.

If you want to prevent a field from being serialized, then you can place
the NonSerialized attribute on the field to keep it from being serialized.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Chuck Bowling said:
When you use the [Serializable] tag are nested classes also serialized?

If so, can you just use a [NonSerialized] tag to exclude them from the
stream?
 
Back
Top