1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-30 19:45:57 +00:00
Lidarr/NzbDrone.Api/SignalR/Serializer.cs

44 lines
1.2 KiB
C#
Raw Normal View History

using System;
using System.IO;
using Microsoft.AspNet.SignalR.Json;
2013-05-10 23:53:50 +00:00
using NzbDrone.Common.Composition;
namespace NzbDrone.Api.SignalR
{
2013-05-10 23:53:50 +00:00
[Singleton]
public class Serializer : IJsonSerializer
{
2013-05-12 15:18:17 +00:00
private readonly Common.Serializer.IJsonSerializer _nzbDroneSerializer;
2013-05-07 05:38:40 +00:00
private readonly JsonNetSerializer _signalRSerializer;
2013-05-12 15:18:17 +00:00
public Serializer(Common.Serializer.IJsonSerializer nzbDroneSerializer)
{
_signalRSerializer = new JsonNetSerializer();
_nzbDroneSerializer = nzbDroneSerializer;
}
public void Serialize(object value, TextWriter writer)
{
if (value.GetType().FullName.StartsWith("NzbDrone"))
{
_nzbDroneSerializer.Serialize(value, writer);
}
else
{
_signalRSerializer.Serialize(value, writer);
}
}
public object Parse(string json, Type targetType)
{
if (targetType.FullName.StartsWith("NzbDrone"))
{
return _nzbDroneSerializer.Deserialize(json, targetType);
}
2013-05-10 23:53:50 +00:00
return _signalRSerializer.Parse(json, targetType);
}
}
}