rspec/rules/S3325/rule.adoc

33 lines
561 B
Plaintext
Raw Normal View History

== Why is this an issue?
Because the use of initializers to set properties and values makes for clearer, more communicative code, it should be preferred for initializing objects and collections.
=== Noncompliant code example
2022-02-04 17:28:24 +01:00
[source,text]
----
var p = new Person();
p.Age = 5; // Noncompliant
p.Name = "John"; // Noncompliant
var l = new List<int>();
l.Add(5); // Noncompliant
l.Add(10); // Noncompliant
----
=== Compliant solution
2022-02-04 17:28:24 +01:00
[source,text]
----
var p = new Person
{
Age = 5,
Name = "John"
};
var l = new List<int> {5, 10};
----