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.
41 lines
1.3 KiB
41 lines
1.3 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 : ClassSerializerBase<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;
|
|
}
|
|
|
|
protected override RefToken DeserializeValue(BsonDeserializationContext context, BsonDeserializationArgs args)
|
|
{
|
|
var value = context.Reader.ReadString();
|
|
|
|
return RefToken.Parse(value);
|
|
}
|
|
|
|
protected override void SerializeValue(BsonSerializationContext context, BsonSerializationArgs args, RefToken value)
|
|
{
|
|
context.Writer.WriteString(value.ToString());
|
|
}
|
|
}
|
|
}
|
|
|