1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-28 19:05:55 +00:00
Radarr/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs
2013-05-12 19:52:55 -07:00

45 lines
No EOL
978 B
C#

using System;
using Marr.Data.Converters;
using Marr.Data.Mapping;
using NzbDrone.Common;
using NzbDrone.Common.Serializer;
namespace NzbDrone.Core.Datastore.Converters
{
public class EmbeddedDocumentConverter : IConverter
{
public object FromDB(ColumnMap map, object dbValue)
{
if (dbValue == DBNull.Value)
{
return DBNull.Value;
}
var stringValue = (string)dbValue;
if (string.IsNullOrWhiteSpace(stringValue))
{
return null;
}
return Json.Deserialize(stringValue, map.FieldType);
}
public object ToDB(object clrValue)
{
if (clrValue == null) return null;
var json = Json.Serialize(clrValue);
return json;
}
public Type DbType
{
get
{
return typeof(string);
}
}
}
}