Object Initialization Property Extension to Returned Objects #7883
Unanswered
hawkerm
asked this question in
Language Ideas
Replies: 1 comment 1 reply
-
https://github.com/dotnet/csharplang/blob/main/meetings/2020/LDM-2020-04-20.md |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This would be a re-use of the object initialization syntax beyond constructors for returned objects from methods. Would be similar to
with
with record types as well, I suppose.Not sure how best to describe this, but it's something I always want to do when I get back objects from factories or other built-in API surfaces which return settings style objects that I'm trying to modify.
e.g. here's a scenario from the Windows API as an example customizing a bunch of paragraph settings from the ITextParagraphFormat interface:
What I'd prefer to do instead like if I had constructed this object is the following:
This saves me from having to retype the variable name, or copy-paste a whole wall of text for increasing number of properties. Instead, the value of the object is more easily seen and grouped in a familiar construct.
This works well with the factory pattern as well, as sometimes that's the only way to get a 'new' construction of an object with some API surfaces, as a developer though I frequently want to modify those outcomes before use. Being able to use a familiar pattern I use for construction of other types would be a great feeling and shortcut to my productivity. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions