From 3436961bb5c01d659d09be134368f4f69460cef9 Mon Sep 17 00:00:00 2001 From: MW Date: Sat, 26 May 2007 13:40:19 +0000 Subject: Start of rewrite 5279! --- Common/XmlRpcCS/XmlRpcResponseSerializer.cs | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Common/XmlRpcCS/XmlRpcResponseSerializer.cs (limited to 'Common/XmlRpcCS/XmlRpcResponseSerializer.cs') diff --git a/Common/XmlRpcCS/XmlRpcResponseSerializer.cs b/Common/XmlRpcCS/XmlRpcResponseSerializer.cs new file mode 100644 index 0000000..72ca568 --- /dev/null +++ b/Common/XmlRpcCS/XmlRpcResponseSerializer.cs @@ -0,0 +1,57 @@ +namespace Nwc.XmlRpc +{ + using System; + using System.Collections; + using System.Xml; + + /// Class responsible for serializing an XML-RPC response. + /// This class handles the response envelope, depending on XmlRpcSerializer + /// to serialize the payload. + /// + public class XmlRpcResponseSerializer : XmlRpcSerializer + { + static private XmlRpcResponseSerializer _singleton; + /// A static singleton instance of this deserializer. + static public XmlRpcResponseSerializer Singleton + { + get + { + if (_singleton == null) + _singleton = new XmlRpcResponseSerializer(); + + return _singleton; + } + } + + /// Serialize the XmlRpcResponse to the output stream. + /// An XmlTextWriter stream to write data to. + /// An Object to serialize. + /// + override public void Serialize(XmlTextWriter output, Object obj) + { + XmlRpcResponse response = (XmlRpcResponse)obj; + + output.WriteStartDocument(); + output.WriteStartElement(METHOD_RESPONSE); + + if (response.IsFault) + output.WriteStartElement(FAULT); + else + { + output.WriteStartElement(PARAMS); + output.WriteStartElement(PARAM); + } + + output.WriteStartElement(VALUE); + + SerializeObject(output, response.Value); + + output.WriteEndElement(); + + output.WriteEndElement(); + if (!response.IsFault) + output.WriteEndElement(); + output.WriteEndElement(); + } + } +} -- cgit v1.1