4 ms·
edit: I should have read further. The more interesting parts happen very late in the article. A lot of what is described is still possible (including the queryi
by Semaphor 5y ago
edit: I should have read further. The more interesting parts happen very late in the article. A lot of what is described is still possible (including the querying) in C#, but other things only in very awkward ways.
Original post follows:
It seems this is almost possible in C#. Missing is the required property proposal [0], so currently the choice is between having everything be optional, or using explicit constructors (which loses most of what is wanted here). But that does not seem like a huge difference:
Member m = new()
{
FirstName = "Kelly",
Books = new()
{
new() { Author = "Hohlbein, Wolfgang" },
new() { Author = "Tchaikovsky, Adrian" }
}
};
Definitions:
public record struct Book
{
public string Author { get; set; }
}
public record struct Member
{
public string FirstName { get; set; }
public List<Book> Books { get; set; }
}
[0]: https://github.com/dotnet/csharplang/issues/3630 https://github.com/dotnet/csharplang/issues/3630