Support the type creation of non-public parameterless constructor
Is your feature request related to a problem? Please describe.
In order to comply with the design specification of domain model classes, we set the parameterless constructor to non-public.
This makes it impossible for me to use the default deserializer.
Describe the solution you'd like
We can refer to EF Core or System.Text.Json(.NET Core 3.1 and earlier versions).
Consider types that support the creation of non-public parameterless constructor.
This is the implementation details: https://github.com/dotnet/corefx/blob/release/3.1/src/System.Text.Json/src/System/Text/Json/Serialization/ReflectionEmitMemberAccessor.cs FYI.
Describe alternatives you've considered
I know that WithObjectFactory(...) method can be used
Additional context Add any other context or screenshots about the feature request here.
Just to make sure I understand what you’re asking is for us to call a non public constructor when a public one does not exist? Shouldn’t be hard to do but I would make it an opt in feature.
Yes, that's right. :)
Like this:
...
ConstructorInfo realMethod = type.GetConstructor(BindingFlags.Public | BindingFlags.NonPublic .....);
...
Ok, I'll try and put something together in a little bit, might be a week or 2 though. Unless you want to take a stab at it.
goooooooooooooooooood !!!
You will be able to enable this feature by calling .EnablePrivateConstructors() on the deserializer builder.
Cool !!!