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
There are plenty of examples where construction of an object involves more than just property settings.
This request is very simple, and tightly scoped, making it an easy addition to compiler logic, and should produce zero confusion for developers who would take advantage of this.
It is a replacement for Fluent-pattern, and can, in most cases, be used entirely in-lieu of Fluent pattern methods (which often require you to write many extension methods, or Builder classes to achieve the simplified notation.
Here's the pattern I am requesting:
new MyType(){Name="Name",Value=value,.Clicked+= HandleClicked
.SetProperty("propName", propValue),// this is for "attached properties" common in UI's (WPF, Xamarin, Avalonia).ApplyStyleByName("styleName"),.SetGridLoc(column, row)// wrapper for another attached property.Bind("propName", modelObject, Mode.TwoWay).PrepareForUse().AddChildren(new ChildType(){// property setters, followed by method calls},new ChildType2(){// property setters, followed by method calls})}
Note that here I've included "event handlers" in this example, as those are really just calling the "Event.Add()" method, and so qualify as method calls.
NOTE: Unlike Fluent pattern, this notation does not require ANY extension methods or builders to enable the notation.
The proposal is for the above to operate the EXACT SAME as it would if all ".method()" calls were simply called from outside the Initialization block using a local variable reference.
It should also be noted, that this proposal enables functionality that would not otherwise be available via calling methods after initialization. In the above example, if you are initializing children INSIDE the Init-Block (which is already supported by C#), then how do you call Methods upon the Parent object BEFORE adding children? Answer: You'd have to resort to Fluent-pattern or some extra builder logic to enable that to happen.
C# should make simple convenient things simple. Making the Init-Block work like a "wither" block (while enforcing a rule that properties must be set first, or at minimum that "init-only" properties must be set first).
The text was updated successfully, but these errors were encountered:
For new feature proposals, however, please raise them for discussion, and only submit a proposal as a pull request if invited to do so by a member of the Language Design Team (a "champion").
There are plenty of examples where construction of an object involves more than just property settings.
This request is very simple, and tightly scoped, making it an easy addition to compiler logic, and should produce zero confusion for developers who would take advantage of this.
It is a replacement for Fluent-pattern, and can, in most cases, be used entirely in-lieu of Fluent pattern methods (which often require you to write many extension methods, or Builder classes to achieve the simplified notation.
Here's the pattern I am requesting:
Note that here I've included "event handlers" in this example, as those are really just calling the "Event.Add()" method, and so qualify as method calls.
NOTE: Unlike Fluent pattern, this notation does not require ANY extension methods or builders to enable the notation.
The proposal is for the above to operate the EXACT SAME as it would if all ".method()" calls were simply called from outside the Initialization block using a local variable reference.
It should also be noted, that this proposal enables functionality that would not otherwise be available via calling methods after initialization. In the above example, if you are initializing children INSIDE the Init-Block (which is already supported by C#), then how do you call Methods upon the Parent object BEFORE adding children? Answer: You'd have to resort to Fluent-pattern or some extra builder logic to enable that to happen.
C# should make simple convenient things simple. Making the Init-Block work like a "wither" block (while enforcing a rule that properties must be set first, or at minimum that "init-only" properties must be set first).
The text was updated successfully, but these errors were encountered: