diff --git a/src/Qowaiv.Bson.MongoDB/QowaivBsonSerializationProvider.cs b/src/Qowaiv.Bson.MongoDB/QowaivBsonSerializationProvider.cs index 60b2355..bcd4df1 100644 --- a/src/Qowaiv.Bson.MongoDB/QowaivBsonSerializationProvider.cs +++ b/src/Qowaiv.Bson.MongoDB/QowaivBsonSerializationProvider.cs @@ -16,7 +16,7 @@ public sealed class QowaivBsonSerializationProvider : IBsonSerializationProvider { IBsonSerializer? serializer = null; - if (TypeHelper.GetCandidateType(type) is not { } tp + if (GetCandidateType(type) is not { } tp || NotSupported.Contains(tp) || Serializers.TryGetValue(tp, out serializer)) { @@ -56,6 +56,20 @@ private static bool IsSupported(IBsonSerializer converter) .GetProperty(nameof(QowaivBsonSerializer.TypeIsSupported), NonPublicInstance)! .GetValue(converter, Array.Empty())!; + [Pure] + private static Type? GetCandidateType(Type? type) + { + return TypeHelper.NotNullable(type) is { } tp && IsSupported(tp) + ? tp + : null; + + static bool IsSupported(Type type) + => !type.IsAbstract + && !type.IsGenericTypeDefinition + && !type.ContainsGenericParameters + && !type.IsGenericTypeDefinition; + } + #pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields diff --git a/test/Qowaiv.Json.UnitTests/Bson.MongoDB/BSON_serialization_provider_specs.cs b/test/Qowaiv.Json.UnitTests/Bson.MongoDB/BSON_serialization_provider_specs.cs index 9a38c59..02654ae 100644 --- a/test/Qowaiv.Json.UnitTests/Bson.MongoDB/BSON_serialization_provider_specs.cs +++ b/test/Qowaiv.Json.UnitTests/Bson.MongoDB/BSON_serialization_provider_specs.cs @@ -21,7 +21,7 @@ public void nullable_FromJson_string_only_SVO() .Should().BeOfType>(); [Test] - public void FromJson_string_only_SVO_class() + public void FromJson_SVO_class() => provider.GetSerializer(typeof(SvoWithFromJsonClass)) .Should().BeOfType>(); @@ -30,21 +30,10 @@ public void Qowaiv_ID() => provider.GetSerializer(typeof(Id)) .Should().BeOfType>>(); - - [Test] - public void Qowaiv_ID_via_behavior() - => provider.GetSerializer(typeof(SomeIdBehavior)) - .Should().BeOfType>>(); - [Test] public void Qowaiv_generic_SVO() => provider.GetSerializer(typeof(Svo)) .Should().BeOfType>>(); - - [Test] - public void Qowaiv_generic_SVO_via_behavior() - => provider.GetSerializer(typeof(SomeSvoBehavior)) - .Should().BeOfType>>(); } public class Gets_null @@ -68,7 +57,7 @@ public void DTO() => provider.GetSerializer(typeof(DtoClass)).Should().BeNull(); } -class Cashes_for_performance_reasons +class Caches_for_performance_reasons { [Test] public void serializers_already_requested()