I have recently implemented a code to accomplish Object to stringObject-to-String. Can you guys suggest any pros and cons with regard to the code.
Any much generalized code would be welcome.?
public static string ObjectToXml(object obj)
{
var oXmlSerializer = new XmlSerializer(obj.GetType());
var oStringWriter = new StringWriter();
var oXmlSerializerNamespaces = new XmlSerializerNamespaces();
oXmlSerializerNamespaces.Add(string.Empty,string.Empty);
var oXmlWriterSettings = new XmlWriterSettings
{
Indent = true,
OmitXmlDeclaration = false,
Encoding = Encoding.GetEncoding("ISO-8859-1")
};
var oXmlWriter = XmlWriter.Create(oStringWriter,oXmlWriterSettings);
oXmlSerializer.Serialize(oXmlWriter, obj, oXmlSerializerNamespaces);
oXmlWriter.Close();
return oStringWriter.ToString();
}