
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
62 lines
1.0 KiB
Plaintext
62 lines
1.0 KiB
Plaintext
== Why is this an issue?
|
|
|
|
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]++``.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,csharp]
|
|
----
|
|
public void MyMethod([DefaultParameterValue(5)] int j) //Noncompliant, useless
|
|
{
|
|
Console.WriteLine(j);
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,csharp]
|
|
----
|
|
public void MyMethod(int j = 5)
|
|
{
|
|
Console.WriteLine(j);
|
|
}
|
|
----
|
|
or
|
|
|
|
[source,csharp]
|
|
----
|
|
public void MyMethod([DefaultParameterValue(5)][Optional] int j)
|
|
{
|
|
Console.WriteLine(j);
|
|
}
|
|
----
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Add the "Optional" attribute to this parameter.
|
|
|
|
|
|
=== Highlighting
|
|
|
|
``++[DefaultParameterValue(...)]++``
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 8 Dec 2015, 10:00:41 Tamas Vajk wrote:
|
|
\[~ann.campbell.2] LGTM
|
|
|
|
endif::env-github,rspecator-view[]
|