rspec/rules/S3450/csharp/rule.adoc

52 lines
904 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
There is no point in providing a default value for a parameter if callers are required to provide a value for it anyway. Thus, ``++[DefaultParameterValue]++`` should always be used in conjunction with ``++[Optional]++``.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
public void MyMethod([DefaultParameterValue(5)] int j) //Noncompliant, useless
{
Console.WriteLine(j);
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
public void MyMethod(int j = 5)
{
Console.WriteLine(j);
}
----
or
2022-02-04 17:28:24 +01:00
[source,csharp]
2021-04-28 16:49:39 +02:00
----
public void MyMethod([DefaultParameterValue(5)][Optional] int j)
{
Console.WriteLine(j);
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::message.adoc[]
include::highlighting.adoc[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]