
## Review A dedicated reviewer checked the rule description successfully for: - [ ] logical errors and incorrect information - [ ] information gaps and missing content - [ ] text style and tone - [ ] PR summary and labels follow [the guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
64 lines
1.5 KiB
Plaintext
64 lines
1.5 KiB
Plaintext
include::../description.adoc[]
|
|
|
|
== How to fix it
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,vbnet,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
Public Class BaseClass
|
|
Public Overridable Sub MyMethod(ByVal Optional i As Integer = 1)
|
|
Console.WriteLine(i)
|
|
End Sub
|
|
End Class
|
|
|
|
Public Class DerivedClass
|
|
Inherits BaseClass
|
|
|
|
Public Overrides Sub MyMethod(ByVal Optional i As Integer = 1)
|
|
' ...
|
|
MyBase.MyMethod() ' Noncompliant: caller's value is ignored
|
|
End Sub
|
|
|
|
Private Shared Function Main(ByVal args As String()) As Integer
|
|
Dim dc As DerivedClass = New DerivedClass()
|
|
dc.MyMethod(12) ' prints 1
|
|
End Function
|
|
End Class
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,vbnet,diff-id=1,diff-type=compliant]
|
|
----
|
|
Public Class BaseClass
|
|
Public Overridable Sub MyMethod(ByVal Optional i As Integer = 1)
|
|
Console.WriteLine(i)
|
|
End Sub
|
|
End Class
|
|
|
|
Public Class DerivedClass
|
|
Inherits BaseClass
|
|
|
|
Public Overrides Sub MyMethod(ByVal Optional i As Integer = 1)
|
|
' ...
|
|
MyBase.MyMethod(i)
|
|
End Sub
|
|
|
|
Private Shared Function Main(ByVal args As String()) As Integer
|
|
Dim dc As DerivedClass = New DerivedClass()
|
|
dc.MyMethod(12) ' prints 12
|
|
End Function
|
|
End Class
|
|
----
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
Microsoft Learn - https://learn.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/procedures/optional-parameters[Optional Arguments (Visual Basic)]
|
|
|
|
include::../rspecator.adoc[]
|