extend object initializer syntax to arbitrary expressions

Topics: C# Language Design
Oct 9, 2015 at 6:27 PM
Edited Oct 9, 2015 at 6:53 PM
i love c#'s object initializers, they save typing, but more importantly they group multiple assignments to the same object hilighting intent and increasing readability.
var foo = new Foo() {
   Feature = "Object Initializers",
   Sentiment = "Love 'em",
   Postscript = "A little limited, though",
};
The problem i have with them is that they only work for the expression "new Foo(...)".

Please extend this syntax to work with any Foo-valued expression:
var foo = Foo.Create() {
   Feature = "Object Initializers",
   Sentiment = "Love 'em",
   Postscript = "Perfect",
};
or more importantly:
var foos =
    from bar in allBars
    select Foo.Create() {
       Bar = bar
    }
which is just not possible today since statements or explicit lambdas aren't allowed in LINQ queries (CS0834: A lambda expression with a statement body cannot be converted to an expression tree)
Oct 11, 2015 at 9:44 PM
Discussions have moved to https://github.com/dotnet/rolslyn/ and there have been opened several issues on this particular matter.