1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-10 04:52:42 +01:00
Radarr/NzbDrone.Core/Datastore/CustomeMapper.cs
Mark McDowall 0ed898b6db IsIgnored will now be checked when adding new episodes to the DB, it will:
- ignore new episodes of a season if that season was already ignored
- ignore new seasons if the previous was ignored
- ignore specials (when a new series is added), if a user chooses to download specials, all new specials will not be ignored

Added tests for IsIgnored and AddEpisode changes.
2011-07-22 17:57:52 -07:00

48 lines
1.8 KiB
C#

using System;
using System.Reflection;
using PetaPoco;
namespace NzbDrone.Core.Datastore
{
public class CustomeMapper : DefaultMapper
{
public override Func<object, object> GetFromDbConverter(Type destinationType, Type sourceType)
{
if ((sourceType == typeof(Int32) || sourceType == typeof(Int64)) && destinationType.IsGenericType && destinationType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
// If it is NULLABLE, then get the underlying type. eg if "Nullable<int>" then this will return just "int"
Type genericArgument = destinationType.GetGenericArguments()[0];
if (genericArgument == typeof(DayOfWeek))
{
return delegate(object s)
{
int value;
Int32.TryParse(s.ToString(), out value);
return (DayOfWeek?)value;
};
}
return delegate(object s)
{
int value;
Int32.TryParse(s.ToString(), out value);
return value;
};
}
return base.GetFromDbConverter(destinationType, sourceType);
}
public override Func<object, object> GetFromDbConverter(PropertyInfo propertyInfo, Type sourceType)
{
//Only needed if using dynamic as the return type from DB, not implemented currently as it has no use right now
//if (propertyInfo == null)
// return null;
return GetFromDbConverter(propertyInfo.PropertyType, sourceType);
}
}
}