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