1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-09 20:42:37 +01:00
Radarr/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs

43 lines
918 B
C#

using System;
using Marr.Data.Converters;
using Marr.Data.Mapping;
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;
return clrValue.ToJson();
}
public Type DbType
{
get
{
return typeof(string);
}
}
}
}