Code inspection: Use 'with' expression to copy struct
This inspection reports struct-copying code where a new value is produced mostly from an existing struct value and only one or a few members are changed. In that case, a with expression is a clearer way to express "copy this value and modify these members".
Example
var point = new Point { X = 1, Y = 2 };
var moved = new Point { X = point.X, Y = 10 };
var point = new Point { X = 1, Y = 2 };
var moved = point with { Y = 10 };
Quick-fix
The with form is shorter and highlights the changed members instead of repeating the copied ones.
30 March 2026