1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-05 18:42:42 +01:00
Radarr/NzbDrone.Core/Datastore/CustomeMapper.cs

48 lines
1.7 KiB
C#
Raw Normal View History

2011-06-15 04:31:41 +02:00
using System;
using PetaPoco;
namespace NzbDrone.Core.Datastore
{
public class CustomeMapper : DefaultMapper
{
public override Func<object, object> GetFromDbConverter(DestinationInfo destinationInfo, Type SourceType)
{
if ((SourceType == typeof(Int32) || SourceType == typeof(Int64)) && destinationInfo.Type.IsGenericType && destinationInfo.Type.GetGenericTypeDefinition() == typeof(Nullable<>))
{
// If it is NULLABLE, then get the underlying type. eg if "Nullable<int>" then this will return just "int"
2011-06-16 08:33:01 +02:00
Type genericArgument = destinationInfo.Type.GetGenericArguments()[0];
if (genericArgument == typeof(DayOfWeek))
2011-06-15 04:31:41 +02:00
{
return delegate(object s)
{
int value;
Int32.TryParse(s.ToString(), out value);
if (value == 0)
{
return null;
}
return (Nullable<DayOfWeek>)value;
};
}
2011-06-16 08:33:01 +02:00
else
{
return delegate(object s)
{
int value;
Int32.TryParse(s.ToString(), out value);
if (value == 0)
{
return null;
}
return value;
};
}
2011-06-15 04:31:41 +02:00
}
return base.GetFromDbConverter(destinationInfo, SourceType);
}
}
}