Parse XML Physical Path to Class

 public static T DeserilizeXML<T>(this string physicalPath) where T : class
        {
            try
            {
                if (!string.IsNullOrEmpty(physicalPath) && !string.IsNullOrWhiteSpace(physicalPath))
                {
                    if (File.Exists(physicalPath))
                    {
                        try
                        {
                            XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<T>));
                            using (TextReader textReader = new StreamReader(physicalPath))
                            {
                                return (T)xmlSerializer.Deserialize(textReader);
                            }
                        }
                        catch (Exception)
                        {
                            return File.ReadAllText(physicalPath).ParseToClass<T>();
                        }
                    }
                }
            }
            catch (Exception)
            {

            }
            return null;
        }
Example:
none

Description

Get XML from Physical Path and Parse into Class

Details

Double click on the code to select all.