mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 18:57:39 -07:00
Better handling of xml errors on tvrage
This commit is contained in:
parent
580585dc10
commit
2bd866f590
7 changed files with 152 additions and 55 deletions
51
NzbDrone.Core/Helpers/XElementHelper.cs
Normal file
51
NzbDrone.Core/Helpers/XElementHelper.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace NzbDrone.Core.Helpers
|
||||
{
|
||||
public static class XElementHelper
|
||||
{
|
||||
public static T ConvertTo<T>(this XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
return default(T);
|
||||
|
||||
if (String.IsNullOrEmpty(element.Value))
|
||||
return default(T);
|
||||
|
||||
var converter = TypeDescriptor.GetConverter(typeof(T));
|
||||
try
|
||||
{
|
||||
return (T)converter.ConvertFromString(element.Value);
|
||||
}
|
||||
|
||||
catch
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
|
||||
public static DayOfWeek? ConvertToDayOfWeek(this XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
return null;
|
||||
|
||||
if (String.IsNullOrWhiteSpace(element.Value))
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
return (DayOfWeek)Enum.Parse(typeof(DayOfWeek), element.Value);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue