1

I have a use case where I am serializing objects over the wire via MSMQ (mostly strings). When I read the object off the queue I want to be able to tell if the user meant for the object to be a XML or a string. I was thinking a good way to do this would just be to check the type. If it's XmlElement than it becomes XML data otherwise it becomes string or CDATA. The reason I don't want to just check to see if the data is valid XML is that sometimes data will be provided that is supposed to be serialized as a string but is in fact valid XML. I want the caller to be able to control the de-serialization into string or XML.

Are there any types that are marked as serializable in the .NET Framework like XElement or XmlElement (both which are not marked serializable)?

Eric Schoonover
  • 47,184
  • 49
  • 157
  • 202

1 Answers1

2

Why don't you just add a property to the class of the serialized object that tells you what it is? I'd propose IsXml.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • I could make a wrapper class... right now the class is just string and I was looking for an alternative that represented an XML element, exists in the framework already, and is serializable. – Eric Schoonover Dec 21 '09 at 20:58
  • and that's what I did. thanks for getting my brain started nobugz :) – Eric Schoonover Dec 21 '09 at 22:11