52 lines
899 B
Plaintext
52 lines
899 B
Plaintext
== Why is this an issue?
|
|
|
|
include::../description.adoc[]
|
|
|
|
=== Exceptions
|
|
|
|
include::../exceptions-dotnet.adoc[]
|
|
|
|
== How to fix it
|
|
|
|
include::../howtofix.adoc[]
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,csharp,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
public class Foo
|
|
{
|
|
private string name = "foobar"; // Noncompliant
|
|
|
|
public string DefaultName { get; } = "foobar"; // Noncompliant
|
|
|
|
public Foo(string value = "foobar") // Noncompliant
|
|
{
|
|
var something = value ?? "foobar"; // Noncompliant
|
|
}
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,csharp,diff-id=1,diff-type=compliant]
|
|
----
|
|
public class Foo
|
|
{
|
|
private const string Foobar = "foobar";
|
|
|
|
private string name = Foobar;
|
|
|
|
public string DefaultName { get; } = Foobar;
|
|
|
|
public Foo(string value = Foobar)
|
|
{
|
|
var something = value ?? Foobar;
|
|
}
|
|
}
|
|
----
|
|
|
|
include::../rspecator-dotnet.adoc[]
|