Fork me on GitHub
TypeName ObjectInitializerAnalyzer
Check Id CC0008
Category Style
Severity Warning

Cause

When possible an object initializer should be used to initialize the properties of an object instead of multiple assignments.

Example

var p = new Person();
p.Name = "Mahmoud";
p.Age = 25;

Code fix

A code fix will be presented to you that will transform the code:

var p = new Person()
{
    Name = "Mahmoud",
    Age = 25
};

Code fix

Related rules

  • CC0009 - Use object initializer (assignment)

See also

TBD