2023-05-03 11:06:20 +02:00
|
|
|
== 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
|
|
|
|
|
2024-02-26 14:03:40 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2024-02-26 14:03:40 +01:00
|
|
|
include::../rspecator-dotnet.adoc[]
|