mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
QualityTypes no longer an enum
This commit is contained in:
parent
49f086cf19
commit
92acb4c049
37 changed files with 585 additions and 247 deletions
|
@ -1,14 +1,28 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
using NzbDrone.Core.Repository.Quality;
|
||||
using PetaPoco;
|
||||
|
||||
namespace NzbDrone.Core.Datastore
|
||||
{
|
||||
public class CustomeMapper : DefaultMapper
|
||||
{
|
||||
public override Func<object, object> GetToDbConverter(Type sourceType)
|
||||
{
|
||||
if (sourceType == typeof(QualityTypes))
|
||||
{
|
||||
return delegate(object s)
|
||||
{
|
||||
var source = (QualityTypes)s;
|
||||
return source.Id;
|
||||
};
|
||||
}
|
||||
|
||||
return base.GetToDbConverter(sourceType);
|
||||
}
|
||||
|
||||
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"
|
||||
|
@ -31,6 +45,17 @@ namespace NzbDrone.Core.Datastore
|
|||
};
|
||||
}
|
||||
|
||||
if ((sourceType == typeof(Int32) || sourceType == typeof(Int64)) && destinationType == typeof(QualityTypes))
|
||||
{
|
||||
return delegate(object s)
|
||||
{
|
||||
int value;
|
||||
Int32.TryParse(s.ToString(), out value);
|
||||
var quality = (QualityTypes)value;
|
||||
return quality;
|
||||
};
|
||||
}
|
||||
|
||||
return base.GetFromDbConverter(destinationType, sourceType);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue