Skip to content

ParameterCanBeByValInspection

Max Dörner edited this page Jun 2, 2019 · 4 revisions

Description: Parameter can be passed by value

Type: CodeInspectionType.CodeQualityIssues

Default severity: CodeInspectionSeverity.Suggestion

This inspection finds procedure parameters that are passed by reference, but never assigned to.

Example:

Parameter foo is passed ByRef, but is never assigned to - passing it ByVal would be more appropriate:

Public Sub DoSomething(ByRef foo As Integer)
    DoSomethingElse foo
End Sub

A ByRef parameter can technically be reassigned by the called procedure, and the modified value is visible to the caller; if a method doesn't assign such a parameter, that parameter can safely be passed by value instead.


QuickFixes

QuickFix: Pass parameter by value

Public Sub DoSomething(ByVal foo As Integer)
    DoSomethingElse foo
End Sub

This quickfix replaces ByRef with ByVal in the method's signature for the unassigned parameter.

Clone this wiki locally