diff --git a/src/MongODM.Core/Serialization/Mapping/CustomSerializerMap.cs b/src/MongODM.Core/Serialization/Mapping/CustomSerializerMap.cs index dd9845c..9847ef0 100644 --- a/src/MongODM.Core/Serialization/Mapping/CustomSerializerMap.cs +++ b/src/MongODM.Core/Serialization/Mapping/CustomSerializerMap.cs @@ -18,7 +18,6 @@ namespace Etherna.MongODM.Core.Serialization.Mapping { internal sealed class CustomSerializerMap : MapBase, ICustomSerializerMapBuilder - where TModel : class { // Constructor. public CustomSerializerMap( diff --git a/src/MongODM.Core/Serialization/Mapping/ICustomSerializerMapBuilder.cs b/src/MongODM.Core/Serialization/Mapping/ICustomSerializerMapBuilder.cs index 5bef944..c9493d9 100644 --- a/src/MongODM.Core/Serialization/Mapping/ICustomSerializerMapBuilder.cs +++ b/src/MongODM.Core/Serialization/Mapping/ICustomSerializerMapBuilder.cs @@ -15,7 +15,6 @@ namespace Etherna.MongODM.Core.Serialization.Mapping { public interface ICustomSerializerMapBuilder - where TModel : class { } } \ No newline at end of file diff --git a/src/MongODM.Core/Serialization/Mapping/IMapRegistry.cs b/src/MongODM.Core/Serialization/Mapping/IMapRegistry.cs index 9197e8b..efafd92 100644 --- a/src/MongODM.Core/Serialization/Mapping/IMapRegistry.cs +++ b/src/MongODM.Core/Serialization/Mapping/IMapRegistry.cs @@ -42,8 +42,7 @@ public interface IMapRegistry : IDbContextInitializable, IFreezableConfig /// Custom serializer /// The new schema ICustomSerializerMapBuilder AddCustomSerializerMap( - IBsonSerializer customSerializer) - where TModel : class; + IBsonSerializer customSerializer); /// /// Register a new schema based on model map @@ -56,8 +55,7 @@ ICustomSerializerMapBuilder AddCustomSerializerMap( IModelMapBuilder AddModelMap( string activeModelMapSchemaId, Action>? activeModelMapSchemaInitializer = null, - IBsonSerializer? customSerializer = null) - where TModel : class; + IBsonSerializer? customSerializer = null); /// /// Get active class map from schemas, or create a default classMap for model type diff --git a/src/MongODM.Core/Serialization/Mapping/MapRegistry.cs b/src/MongODM.Core/Serialization/Mapping/MapRegistry.cs index 42ea182..c5bfb9e 100644 --- a/src/MongODM.Core/Serialization/Mapping/MapRegistry.cs +++ b/src/MongODM.Core/Serialization/Mapping/MapRegistry.cs @@ -59,7 +59,7 @@ public void Initialize(IDbContext dbContext, ILogger logger) // Methods. public ICustomSerializerMapBuilder AddCustomSerializerMap( - IBsonSerializer customSerializer) where TModel : class => + IBsonSerializer customSerializer) => ExecuteConfigAction(() => { ArgumentNullException.ThrowIfNull(customSerializer, nameof(customSerializer)); @@ -74,8 +74,7 @@ public ICustomSerializerMapBuilder AddCustomSerializerMap( public IModelMapBuilder AddModelMap( string activeModelMapSchemaId, Action>? activeModelMapSchemaInitializer = null, - IBsonSerializer? customSerializer = null) - where TModel : class => + IBsonSerializer? customSerializer = null) => ExecuteConfigAction(() => { // Register and add schema configuration. diff --git a/src/MongODM.Core/Serialization/Mapping/ModelMap.cs b/src/MongODM.Core/Serialization/Mapping/ModelMap.cs index d6f7d2d..5e48cca 100644 --- a/src/MongODM.Core/Serialization/Mapping/ModelMap.cs +++ b/src/MongODM.Core/Serialization/Mapping/ModelMap.cs @@ -38,8 +38,9 @@ protected ModelMap( { DbContext = dbContext ?? throw new ArgumentNullException(nameof(dbContext)); - // Verify if have to use proxy model. - if (modelType != typeof(object) && + // Verify if uses proxy model. + if (modelType.IsClass && + modelType != typeof(object) && !modelType.IsAbstract && !dbContext.ProxyGenerator.IsProxyType(modelType)) { @@ -202,7 +203,6 @@ private MemberMap BuildMemberMap( [SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope")] internal sealed class ModelMap : ModelMap, IModelMapBuilder - where TModel : class { // Constructor. public ModelMap(IDbContext dbContext) diff --git a/src/MongODM.Core/Serialization/Serializers/ModelMapSerializer.cs b/src/MongODM.Core/Serialization/Serializers/ModelMapSerializer.cs index caeef61..add8e04 100644 --- a/src/MongODM.Core/Serialization/Serializers/ModelMapSerializer.cs +++ b/src/MongODM.Core/Serialization/Serializers/ModelMapSerializer.cs @@ -29,11 +29,9 @@ namespace Etherna.MongODM.Core.Serialization.Serializers { public class ModelMapSerializer : SerializerBase, - IBsonSerializer, IBsonDocumentSerializer, IBsonIdProvider, IModelMapsHandlingSerializer - where TModel : class { // Fields. private IDiscriminatorConvention _discriminatorConvention = default!; @@ -72,7 +70,7 @@ public override TModel Deserialize(BsonDeserializationContext context, BsonDeser if (context.Reader.CurrentBsonType == BsonType.Null) { context.Reader.ReadNull(); - return null!; + return default!; } // Find pre-deserialization informations. @@ -139,15 +137,15 @@ public override TModel Deserialize(BsonDeserializationContext context, BsonDeser * In this case, don't add any not-proxy models in cache. */ if (!dbContext.SerializerModifierAccessor.IsNoCacheEnabled && - GetDocumentId(model, out var id, out _, out _) && id != null && - dbContext.ProxyGenerator.IsProxyType(model.GetType())) + dbContext.ProxyGenerator.IsProxyType(model!.GetType()) && + GetDocumentId(model, out var id, out _, out _) && id != null) { if (dbContext.DbCache.LoadedModels.ContainsKey(id)) { var fullModel = model; model = (TModel)dbContext.DbCache.LoadedModels[id]; - if (((IReferenceable)model).IsSummary) + if (((IReferenceable)model!).IsSummary) ((IReferenceable)model).MergeFullModel(fullModel); } else