I've seen several examples of the new records feature in C# 9.0. I.e., being able to update individual properties to create new immutable records. What I'm curious to know is if the with syntax allows me to insert new entries into something like a dictionary, creating a new immutable dictionary along with all the sibling properties that make up the record.
For example, can I do something like this?
public record Person
{
public string Name;
}
public record Car
{
public string Model;
public Dictionary<string, Person> Riders;
}
var car = new Car
{
Model = "Delorean",
Riders = ("driver", new Person { Name = "Doc Brown" })
};
var newCar = car with
{
Riders with ("passenger1", new Person { Name = "Marty McFly" })
};