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

XML TO Class

Parse XML String to Class

Source

public static T ParseToClass<T>(this string xml) where T : class
{
    try
    {
        if (!string.IsNullOrEmpty(xml) && !string.IsNullOrWhiteSpace(xml))
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
            using (StringReader stringReader = new StringReader(xml))
            {
                return (T)xmlSerializer.Deserialize(stringReader);
            }
        }
    }
    catch (Exception)
    {

    }
    return null;
}

Example

None

Author: Keyur Panchal

Submitted on: 3 nov 2016

Language: C#

Type: XML String

Views: 3970