You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sonarr/NzbDrone.Core/Datastore/CustomeMapper.cs

36 lines
1.4 KiB

14 years ago
using System;
using PetaPoco;
namespace NzbDrone.Core.Datastore
{
public class CustomeMapper : DefaultMapper
{
public override Func<object, object> GetFromDbConverter(DestinationInfo destinationInfo, Type sourceType)
14 years ago
{
if ((sourceType == typeof(Int32) || sourceType == typeof(Int64)) && destinationInfo.Type.IsGenericType && destinationInfo.Type.GetGenericTypeDefinition() == typeof(Nullable<>))
14 years ago
{
// If it is NULLABLE, then get the underlying type. eg if "Nullable<int>" then this will return just "int"
Type genericArgument = destinationInfo.Type.GetGenericArguments()[0];
if (genericArgument == typeof(DayOfWeek))
14 years ago
{
return delegate(object s)
{
int value;
Int32.TryParse(s.ToString(), out value);
return (DayOfWeek?)value;
14 years ago
};
}
return delegate(object s)
{
int value;
Int32.TryParse(s.ToString(), out value);
return value;
};
14 years ago
}
return base.GetFromDbConverter(destinationInfo, sourceType);
14 years ago
}
}
}