This is different. If you want to serialize an object directly in watch window, without having to goto immediate window, here is the code.
Utility.SerializeObject(quoteByIdResponse)
Utility.SerializeObject(quoteByIdResponse)
Code Snippet
- public static byte[] SerializeObject(object pObject)
- {
- byte[] xmlvalue = new Byte[0];
- MemoryStream memoryStream = new MemoryStream();
- XmlSerializer xs = new XmlSerializer(pObject.GetType());
- XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
- try
- {
- xs.Serialize(xmlTextWriter, pObject);
- memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
- xmlvalue = memoryStream.ToArray();
- }
- catch (Exception e)
- {
- }
- finally
- {
- xmlTextWriter.Close();
- xmlTextWriter = null;
- memoryStream.Close();
- memoryStream = null;
- xs = null;
- }
- return xmlvalue;
- }
- public static string SerializeObjectString(object pObject)
- {
- string XmlString = null;
- StringWriter sw = new StringWriter();
- XmlSerializer xs = new XmlSerializer(pObject.GetType());
- try
- {
- xs.Serialize(sw, pObject);
- XmlString = sw.ToString();
- }
- catch (Exception e)
- {
- XmlString = e.Message;
- if (e.InnerException != null)
- XmlString += " Inner Exception:" + e.InnerException.Message;
- }
- finally
- {
- xs = null;
- }
- return XmlString;
- }
No comments:
Post a Comment