Skip to content

Properties not instantiated when a constructor with parameters is present #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ard2025
Copy link
Collaborator

@Ard2025 Ard2025 commented Aug 19, 2025

Fixes #101, Class properties are not instantiated when there is a constructor with parameter. In this way the data from the indexeddb is deserialized while giving the option to do contructor time operations on a select amount of properties without having to specify all of them. Fields this way will still be overwritten by the custon deconstructor, but it can be helpfull to do operations on nonmapped properties in the constructor.

@Ard2025 Ard2025 self-assigned this Aug 19, 2025
@Ard2025 Ard2025 added bug Something isn't working and removed bug Something isn't working labels Aug 19, 2025
@HarvieKrumpet
Copy link

just as newtonsoft/system.text solves this with [JsonConstructor] you should have a [MagicConstructor] which will tell you which constructor is yours to use. I have never seen the deserializer fill in the constructor parameters anyway they are always null. The deserializer in any case should not "guess" which constructer to use. or at very the very least always pick the parameterless constructor. Most of my database destined classes are heavily nested with other classes that cannot be filled in from the parent construction anyway.
So just looking for your system to ignore all but the parameterless constructor. You could actually just peek into the attributes and specifically look for the newtonsoft or system.text jsonconstructor without creating a new attribute. I also havent seen a case where [MagicNotMapped] is used when [JsonIgnore] isn't also present. you could just adopt these attributes. Would make it almost plug and play, otherwise I have to track down every [jsonignore] and edit it as [jsonignore,magicnotmapped]

@Ard2025 Ard2025 marked this pull request as draft August 19, 2025 22:37
@Ard2025
Copy link
Collaborator Author

Ard2025 commented Aug 19, 2025

I think i have misunderstood the situation, as most of the text was about the properties not beiing filled.

Around the edited lines, the constuctor args are passed into the constructor so then the parameter name and type match the property the value can be used in the constructor.

As for the system.text.json attributes, It would be nice indeed to integrate those. il take a look at it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parameterized Constructors
2 participants