-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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: Property Setters as Methods #9103
Comments
Anyway, this can be an alternative to #133, however, it dictates fluent API style. Not to mention that this is something towards easing mutation which isn't considered as a theme for now, I believe. |
Another problem with this proposal is that properties can return delegates. If your example had been Also, var result = Foo.MakeAFoo()
..set_Bar("Hello")
..set_Baz(1234)
..ToString(); |
This proposal deals strictly with the setter accessors, and they return |
@HaloFour I think that @DerpMcDerp's point was that when you write |
@svick Ah yes, that is a good point. Pretty much shuts down this proposal. Oh well, it was just spaghetti against the wall. |
@DerpMcDerp the way method cascading is usually implemented, it's not limited to setters, and uses the usual operators. So the example would be more like this: var result = Foo.MakeAFoo()
..Bar = "Hello"
..Baz = 1234
.ToString(); // the last one doesn't use ".." as we want it returned into result |
C# isn't a whitespace sensitive language which makes that syntax quite ambiguous. var result = Foo.MakeAFoo()..Bar="Hello"..Baz=1234.ToString(); |
Edit: comment was wrong/incomplete. |
This is a total spaghetti proposal. 🍝
I've seen a number of proposals around fluent APIs and how the language should be modified to extend initialization or reuse the target object, often with either messy grammar results or features that have been intentionally declined from the language for years.
What if the C# compiler would permit using property setters on arbitrary types as if they were methods that accepted the proposed value as a parameter and returned the parent instance?
It might get a little ugly with indexers or events, though.
The text was updated successfully, but these errors were encountered: