mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
48 lines
1.4 KiB
// ==========================================================================
|
|
// RefTokenSerializer.cs
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex Group
|
|
// All rights reserved.
|
|
// ==========================================================================
|
|
|
|
using System;
|
|
using MongoDB.Bson.Serialization;
|
|
using MongoDB.Bson.Serialization.Serializers;
|
|
|
|
namespace Squidex.Infrastructure.MongoDb
|
|
{
|
|
public class RefTokenSerializer : SerializerBase<RefToken>
|
|
{
|
|
private static readonly Lazy<bool> Registerer = new Lazy<bool>(() =>
|
|
{
|
|
BsonSerializer.RegisterSerializer(new RefTokenSerializer());
|
|
|
|
return true;
|
|
});
|
|
|
|
public static bool Register()
|
|
{
|
|
return !Registerer.IsValueCreated && Registerer.Value;
|
|
}
|
|
|
|
public override RefToken Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
|
|
{
|
|
var value = context.Reader.ReadString();
|
|
|
|
return value != null ? RefToken.Parse(value) : null;
|
|
}
|
|
|
|
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, RefToken value)
|
|
{
|
|
if (value != null)
|
|
{
|
|
context.Writer.WriteString(value.ToString());
|
|
}
|
|
else
|
|
{
|
|
context.Writer.WriteNull();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|