Serialization and text formatting

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

Chuck Bowling

Up front, i'm not very good with serialization and i'm not quite sure what
capabilities it has.

I have an app that outputs a text file with this format:

<root>
\t <node1>
\t\t text...
\t <\node1>
\t <node2>
\t\t text...
\t <\node2>
</root>

The tags and text for node1 and 2 are generated in the classes Node1 and 2.
The Root class adds root tags and tab formatting to the inner Nodes and
text. The Node classes add an additional layer of tab formatting to their
respective content.

Does it make sense to try and make the outer and inner classes serializable?
If so, how would i add the padding in the parent class?
 
I'm not sure what you mean. If node1, node2 and root are class and root
has node1 and node2 properties then you can serialize then as you have
described and the framework classes will format them nicely for you.

something like this :

XmlSerializer serializer = new XmlSerializer(typeof(Root));
TextWriter tw = new StreamWriter(filename);
serializer.Serialize(tw, _root);
tw.Close();

Add the [Serializable()] attribute to your classes

HTH.
 
Back
Top