Code inspection: Use 'with' expression to copy anonymous object
This inspection reports anonymous object creation where most members are copied from an existing anonymous object and only a few values change. In that case, a with expression expresses the copy-and-modify intent more directly.
Example
var source = new { A = 1, B = true, C = "abc" };
var copy = new { A = source.A, B = false, C = source.C };
var source = new { A = 1, B = true, C = "abc" };
var copy = source with { B = false };
Quick-fix
A with expression removes repeated member copies and makes the changed values stand out.
30 March 2026