You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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).
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!
The text was updated successfully, but these errors were encountered:
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:
_{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).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!The text was updated successfully, but these errors were encountered: