1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-29 03:15:19 +00:00
Radarr/NzbDrone.Core/Datastore/Converters/EmbeddedDocumentConverter.cs

43 lines
918 B
C#
Raw Normal View History

using System;
using Marr.Data.Converters;
using Marr.Data.Mapping;
2013-05-12 15:18:17 +00:00
using NzbDrone.Common.Serializer;
namespace NzbDrone.Core.Datastore.Converters
{
public class EmbeddedDocumentConverter : IConverter
{
2013-04-17 23:32:06 +00:00
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);
}
}
}
}