with Expression
with Operator provides nondestructive mutation of the record using copy-on-write approach. .NEXT Metaprogramming provides special expression type to support the operator:
using DotNext.Linq.Expressions;
using System.Linq.Expressions;
record class MyRecord(int X);
Expression x = new MyRecord(42).Const();
Expression mutation = x.With(new()
{
{ "X", 52.Quoted }
});
With extension method generates the expression equivalent to the following C# expression:
MyRecord mutation = x with { X = 52 };
Mutation expression supports record classes and record value types.