Implementing IFormatter for Custom Formatter

E

Eric Workman

Hi Everyone-

I would like to implement the IFormatter class to create a custom
formatter that essentially does exactly what the
System.Xml.Serialization.XmlSerializer does, but also would allow for
the functionality of ISerializable (GetObjectData, and De-Serialization
Constructor) so that I have more control over the Xml spit out and can
include anything I would like rather than only public variables and the
likes. I don't want to use the SoapFormatter because the Xml coming out
of that is not simple enough for my purposes.

Has anyone implemented IFormatter before and can anyone point me in the
right direction for help with this, I have done quite a bit of searching
and have found very little.

Thanks in advance,

Eric Workman
 
N

Nicholas Paldino [.NET/C# MVP]

Eric,

While the SoapFormatter might seem complex, you really should use it if
you are going to use XML. The reason for this is that if you use
serialization, you have to capture things like internal references, circular
references, etc, etc, which the SoapFormatter handles already. It's a
little bit like a catch 22. If your structure is so simple that you can use
XmlSerializer, then use that. However, if you need more detailed state
information, you want to use XmlSeralizer, without the complexity of the
SoapFormatter, which handles all of the complex situations that might arise.

I would recommend using the SoapFormatter, and applying an XSLT
transform if you need a "simpler" version. Either that, or make it so that
your classes can be serialized just by setting public properties so that you
may use the XmlSerializer class to serialize them.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top