-
-
Save VincentH-Net/c7568727517c4ef4f622815a580316d9 to your computer and use it in GitHub Desktop.
// C# vNext markup friendly | |
enum Row { Icon, Prompt, Header, Entry } | |
void Build() => Content = new Grid | |
{ | |
RowDefinitions = Rows.Define( | |
(Icon , Auto), | |
(Prompt, Auto), | |
(Header, 50 ), | |
(Entry , Auto) | |
), | |
{ | |
Image { } | |
.Row (Icon) .CenterH () | |
.Bind (vm.Icon), | |
Label { LineBreakMode = WordWrap } | |
.Row (Prompt) .TextCenterH () | |
.Bind (vm.RegistrationPrompt), | |
Label { Text = "CODE" } | |
.Row (Header) .Bottom (), | |
Entry { Placeholder = "123456", Keyboard = Numeric } | |
.Row (Entry) .Margins (left: 10) | |
.Bind (vm.RegistrationCode) | |
} | |
}; | |
// C# 8 | |
void Build() => Content = new Grid | |
{ | |
RowDefinitions = Rows.Define( | |
(Row.Icon , Auto), | |
(Row.Prompt, Auto), | |
(Row.Header, 50 ), | |
(Row.Entry , Auto) | |
), | |
Children = { | |
new Image { } | |
.Row (Row.Icon) .CenterH () | |
.Bind (nameof(vm.Icon)), | |
new Label { LineBreakMode = LineBreakMode.WordWrap } | |
.Row (Row.Prompt) .TextCenterH () | |
.Bind (nameof(vm.RegistrationPrompt)), | |
new Label { Text = "CODE" } | |
.Row (Row.Header) .Bottom (), | |
new Entry { Placeholder = "123456", Keyboard = Keyboard.Numeric } | |
.Row (Row.Entry) .Margins (left: 10) | |
.Bind (nameof(vm.RegistrationCode)) | |
} | |
}; |
Could we reduce repetition in nested object initializers?
(e.g. in a declarative UI markup expression, but useful when new-ing up any tree of objects)
-
Allow to omit
new
in initializers below the tree root.
So havenew
on the root, but not required to repeatnew
for each nested child or content object. -
Allow to indicate a default initialization property for a type (collection or single "content property"),
so that property name can be omitted in an initialization expression. E.g.new Grid { Children = { new Label { }, new Button { } } }
could be like:
new Grid { { new Label { }, new Button { } } }
or even:
new Grid { new Label { }, new Button { } }
and when combined with 1):
new Grid { Label { }, Button { } }
-
Allow to omit the parameter type when passing in a parameter value (SwiftUI uses
.
).
To be used when passing in an enum value or a class static member to a parameter.
(also useful outside expression trees) e.g.Alignment = Alignment.Left
could be:
Alignment = .Left
where
Alignment.Left
is either an enum value or a static class member.
When the . is entered, Intellisense starts just as if the full type name was entered before the .
Nameof can sort-of be eliminated in C# 10 with the
[CallerArgumentExpression]
attribute.