Post-initialization code for classes, records and structs #7885
-
The new language features associated with primary constructors are extremely attractive. In addition, the old capabilities of initializers are in great demand, especially after adding It would be great to have a post-initialization option, something like:
or for initializer
Now there are ways to get around this using a instance method like Most likely, changes will be needed here not only in the language but also in the .net, although I could be wrong. But this was done during implementation |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 2 replies
-
https://github.com/dotnet/csharplang/blob/main/meetings/2020/LDM-2020-05-04.md#final-initializers |
Beta Was this translation helpful? Give feedback.
-
Is there any update on this topic? The above links are without news. And this functionality would be very useful, since now the use of primary constructors, positional records, and the "with" operator is limited to situations where validation is not needed. And validation is needed very often, and even where it is not needed, teams are in no hurry to use new language features, since validation may be required later and they do not want to multiply approaches of class/record building. |
Beta Was this translation helpful? Give feedback.
-
I also think that this would be useful.
I think that this would be useful in general classes too. Virtual methods shouldn't be called in a constructor. But since this is a method call after construction, the programmer can do any extra setup with virtual method calls here. |
Beta Was this translation helpful? Give feedback.
-
I solved this problem by using a simple |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
#6591