www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 19115] New: Object and Collection Initializers


          Issue ID: 19115
           Summary: Object and Collection Initializers
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: black80 bk.ru

Add initialization lists to D. 
it can be useful in many case: JSON, GUI..
  auto lbl = new Label { Text: "hello", Color: Colors.red };

and even more
I think that it should be extended like WITH-keyword in some languages 
(lbl is variable from code above, it's created already, we just want change
some props):
  lbl = { Text: "hello again", Color: Colors.green }; // no temporary vars
// Text & Color belong to "lbl" variable. same as
  lbl.Text = "hello again";
  lbl.Color = Colors.green;
// colon":" that means assign"=" looks a little bit weird imo, but like in
or same as "with" keyword in some unknown language
  with lbl {
    Text = "hello again",
    Color = Colors.green,

Jul 24 2018