Proposal: Introduction of Object Statement Blocks #8471
Unanswered
BN-KS
asked this question in
Language Ideas
Replies: 3 comments 11 replies
-
I like this, specially when used with the fluent pattern. |
Beta Was this translation helpful? Give feedback.
0 replies
-
How would this work with |
Beta Was this translation helpful? Give feedback.
8 replies
-
The initial use case for me was to help stay more DRY as I hate repeating myself when coding so whenever I do, I start to think of ways in which things could be better or more streamlines.
Remember it's not lazy, it's just efficient ;) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This Proposal is to add Object Statement Blocks to C# where the object.{/statements/} is made generally available as a syntax.
Example:
This could be used in conjunction with Object Initializers. This could allow for even more flexibility, letting developers choose the most appropriate syntax for their needs:
Additionally you could use encapsulation and do this:
This encapsulation would allow the code block to be applied to either the existing or the new object, resulting in a significantly cleaner syntax and reduced code.
Benefits of This Proposal:
Current Workarounds
Developers currently handle complex initializations through multiple steps, resulting in code that may be less readable. Our proposal aims to provide a cleaner, more concise way to achieve the same outcomes.
This is different than the request for expression blocks here:
#3086
And sort of related here:
#5808
But this feature would be notably and distinctly different
Beta Was this translation helpful? Give feedback.
All reactions