AutoConstructor
AutoConstructor copied to clipboard
Add addParameterless option, fix spelling
Add addParameterless option - implement https://github.com/k94ll13nn3/AutoConstructor/issues/119
:this() call calling generated parameterless constructor is never emmited because:
- that wouldn't achieve anything as there is no code in this constructor
- generated constructor is marked as obsolete to avoid direct, so code would not compile
| Anything to inject? | addParameterless | Generation result |
|---|---|---|
| No | False | Analyzer error |
| No | True | Only empty ctor |
| Yes | False | Ctor with arguments |
| Yes | True | Two ctors: empty and with arguments |
changelog:
## [5.4.0] - 2024-05-21
### Added
- Add `addParameterless` option on `AutoConstructor` attribute to generate parameterless constructor for serialization use.
- Add analyzer for base type parameterless constructor existence when using `addParameterless` option
Thanks, I will take a look this week. Just so you know, the CHANGELOG is automatically generated from the Github releases so your changes will be overridden.
I think that options must be provided to
- remove the obsolete attribute if wanted
- customize the obsolete message
I don't want this package to be linked to "serialization", and generating a parameterless constructor can be useful outside this context so this should be possible.
can we do this via project level settings:
AutoConstructor_MarkParameterlessConstructorAsObsolete (bool) AutoConstructor_ParameterlessConstructorObsoleteMessage (string)
and what are the default values then?
specifying these options with every [AutoConstructor] attribute usage would be as much boilerplate as just writing the constructor itself without any generator.
can we do this via project level settings:
AutoConstructor_MarkParameterlessConstructorAsObsolete (bool) AutoConstructor_ParameterlessConstructorObsoleteMessage (string)
Yes that is what I was thinking
and what are the default values then?
specifying these options with every [AutoConstructor] attribute usage would be as much boilerplate as just writing the constructor itself without any generator.
The default can be what you already defined (so true for the obsolete and the comment that you already made).
Added these two options as discussed.
I agree that passing around a boolean flag is not very elegant - here is an alternative implementation by having two different methods https://github.com/DomasM/AutoConstructor/commit/01f475580a6492bff7490e387284a5952fa9cd62 if this is preferred, I can amend that commit to this branch
It's ok, you can leave it like it is. I will try merge it and release it before the end of the week.
noticed that addDefaultBaseAttribute option is not handled correctly, added test and moved to separate generation methods