Skip to content
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

[Proposal] ReadOnly As InitOnly Properties #614

Open
VBAndCs opened this issue Feb 28, 2022 · 0 comments
Open

[Proposal] ReadOnly As InitOnly Properties #614

VBAndCs opened this issue Feb 28, 2022 · 0 comments

Comments

@VBAndCs
Copy link

VBAndCs commented Feb 28, 2022

I think there is no need at all to add an init-only setter to VB (nor C# in fact!).
The readonly property can do the two jobs it perfectly, as the compiler can use naming convention of the back-filed to init the property as follows:

  1. If the filed name is _{Prpp Name}, which is the case of auto properties, then the compiler can use the back filed to set the property to value provided in Initialization expression and in the With expression (that I hope to be added to the language).
  2. If we need to forbid users from initializing some readonly properties, we can mark it with <InitOnly(Flase)>.

And that is it. No need to confuse users with a new keyword and a new setter!
Practically, I implemented my RecGen to treat all ReadOnlly properties as if that are Init-Only, by optionally initializing them throw the Constructor or the With method. I may allow to define positional props as InitOnly instead of readonly if it is desired to omit ReadOnly Properties form the param list of the With method. This shows you that VB is already capable of providing the Init-only functionality without making any change to the property syntax!
In fact I hope Vb some day support my own design of Records, as it is more capable than the C# design, esp when combined with the partial classes to supply more parts such as events.
I may propose this after the next version, when I am thinking of allowing crating Shared Classes with the positional syntax!

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

No branches or pull requests

1 participant