rspec/rules/S1192/csharp/rule.adoc

44 lines
788 B
Plaintext
Raw Normal View History

2020-06-30 12:47:33 +02:00
include::../description.adoc[]
== Noncompliant Code Example
----
public class Foo
{
private string name = "foobar"; // Noncompliant
public string DefaultName { get; } = "foobar"; // Noncompliant
2021-01-21 04:09:13 +00:00
public void Foo(string value = "foobar") // Noncompliant
2020-06-30 12:47:33 +02:00
{
var something = value ?? "foobar"; // Noncompliant
}
}
----
== Compliant Solution
----
public class Foo
{
private const string Foobar = "foobar";
private string name = Foobar;
public string DefaultName { get; } = Foobar;
2021-01-21 04:09:13 +00:00
public void Foo(string value = Foobar)
2020-06-30 12:47:33 +02:00
{
var something = value ?? Foobar;
}
}
----
== Exceptions
The following are ignored:
2020-06-30 12:47:33 +02:00
* literals with fewer than 5 characters
* literals matching one of the parameter names
* literals used in attributes