rspec/rules/S1192/csharp/rule.adoc

52 lines
899 B
Plaintext
Raw Normal View History

== Why is this an issue?
2020-06-30 12:47:33 +02:00
include::../description.adoc[]
2023-10-11 11:41:24 +02:00
=== Exceptions
include::../exceptions-dotnet.adoc[]
2023-10-11 11:41:24 +02:00
== How to fix it
include::../howtofix.adoc[]
2020-06-30 12:47:33 +02:00
2023-10-11 11:41:24 +02:00
=== Code examples
==== Noncompliant code example
[source,csharp,diff-id=1,diff-type=noncompliant]
2020-06-30 12:47:33 +02:00
----
public class Foo
{
private string name = "foobar"; // Noncompliant
public string DefaultName { get; } = "foobar"; // Noncompliant
2021-01-23 04:07:47 +00:00
public Foo(string value = "foobar") // Noncompliant
2020-06-30 12:47:33 +02:00
{
var something = value ?? "foobar"; // Noncompliant
}
}
----
2023-10-11 11:41:24 +02:00
==== Compliant solution
2020-06-30 12:47:33 +02:00
2023-10-11 11:41:24 +02:00
[source,csharp,diff-id=1,diff-type=compliant]
2020-06-30 12:47:33 +02:00
----
public class Foo
{
private const string Foobar = "foobar";
private string name = Foobar;
public string DefaultName { get; } = Foobar;
2021-01-23 04:07:47 +00:00
public Foo(string value = Foobar)
2020-06-30 12:47:33 +02:00
{
var something = value ?? Foobar;
}
}
----
include::../rspecator-dotnet.adoc[]