ExtensionMethod.NET Home of 816 C#, Visual Basic, F# and Javascript extension methods

Class to XML

Parse Class to XML

Source

public static string ToXml<T>(this T value) where T : class
{
    try
    {
        XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
        using (StringWriter stringWriter = new StringWriter())
        {
            xmlSerializer.Serialize(stringWriter, value);
            return stringWriter.ToString();
        }
    }
    catch (Exception)
    {

    }
    return null;
}

Example

none

Author: Keyur Panchal

Submitted on: 3 nov 2016

Language: C#

Type: Class, XML

Views: 1821