Code inspection: Place assignment expression into block
This inspection reports an assignment-like expression used directly as a standalone side effect when the configured syntax style prefers putting it into a block. The goal is to make side effects more explicit in expression-bodied members, lambdas, and single-statement control-flow branches.
Example
class Enblock
{
public Enblock(string name) => Name = name;
public string Name { get; set; }
public void Method()
{
Action action = () => value = 42;
if (value > 0)
value = 53;
}
private int value;
}
class Enblock
{
public Enblock(string name)
{
Name = name;
}
public string Name { get; set; }
public void Method()
{
Action action = () => { value = 42; };
if (value > 0)
{
value = 53;
}
}
private int value;
}
Quick-fix
The quick-fix wraps the assignment expression in a block without changing behavior.
13 April 2026