From 78d972e6fdadf70684f832b99ab852ed89b72557 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 25 Jul 2022 11:23:25 +0200 Subject: [PATCH] Added missing file. --- .../MongoDb/BsonDefaultConventions.cs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 backend/src/Squidex.Infrastructure.MongoDb/MongoDb/BsonDefaultConventions.cs diff --git a/backend/src/Squidex.Infrastructure.MongoDb/MongoDb/BsonDefaultConventions.cs b/backend/src/Squidex.Infrastructure.MongoDb/MongoDb/BsonDefaultConventions.cs new file mode 100644 index 000000000..efb01a5c4 --- /dev/null +++ b/backend/src/Squidex.Infrastructure.MongoDb/MongoDb/BsonDefaultConventions.cs @@ -0,0 +1,40 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using MongoDB.Bson; +using MongoDB.Bson.Serialization.Conventions; + +namespace Squidex.Infrastructure.MongoDb +{ + public static class BsonDefaultConventions + { + private static bool isRegistered; + + public static void Register() + { + try + { + + if (isRegistered) + { + return; + } + + ConventionRegistry.Register("IgnoreExtraElements", new ConventionPack + { + new IgnoreExtraElementsConvention(true) + }, t => true); + + isRegistered = true; + } + catch (BsonSerializationException) + { + return; + } + } + } +}