1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-27 10:07:10 +00:00
Lidarr/NzbDrone.Core/Datastore/Converters/QualityIntConverter.cs
2013-03-26 01:03:28 -07:00

43 lines
No EOL
986 B
C#

using System;
using Marr.Data.Converters;
using Marr.Data.Mapping;
using NzbDrone.Core.Qualities;
namespace NzbDrone.Core.Datastore.Converters
{
public class QualityIntConverter : IConverter
{
public object FromDB(ColumnMap map, object dbValue)
{
if (dbValue == DBNull.Value)
{
return Quality.Unknown;
}
var val = Convert.ToInt32(dbValue);
return (Quality)val;
}
public object ToDB(object clrValue)
{
if(clrValue == null) return 0;
if(clrValue as Quality == null)
{
throw new InvalidOperationException("Attempted to save a quality that isn't really a quality");
}
var quality = clrValue as Quality;
return (int)quality;
}
public Type DbType
{
get
{
return typeof(int);
}
}
}
}