Skip to content

Commit a6bf7e2

Browse files
committed
#1942 - AssignedByValParameter new QuickFix
Added QuickFix to replace ByVal parameter with local copy. Provides a dialog to retrieve a user provided name. Refactored variable name validations to avoid duplicate code and standardize validations for 'UseMeaningfulName' inspections and user's variable name input for this quickfix. Refactored validations to a POCO 'VariableNameValidator'.
1 parent 56130cb commit a6bf7e2

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

RetailCoder.VBE/Inspections/QuickFixes/AssignedByValParameterQuickFix.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public AssignedByValParameterQuickFix(Declaration target, QualifiedSelection sel
2323
: base(target.Context, selection, InspectionsUI.AssignedByValParameterQuickFix)
2424
{
2525
_target = target;
26-
_localCopyVariableName = "local" + CapitalizeFirstLetter(_target.IdentifierName);
2726
_forceUseOfSuggestedName = false;
27+
_localCopyVariableName = string.Empty;
2828

2929
_originalCodeLines = GetMethodLines();
3030
}
@@ -40,7 +40,16 @@ public void TESTONLY_FixUsingAutoGeneratedName()
4040

4141
public override void Fix()
4242
{
43-
GetLocalCopyVariableNameFromUser();
43+
if (_forceUseOfSuggestedName)
44+
{
45+
_localCopyVariableName = AutoSuggestedName();
46+
IsCancelled = false;
47+
}
48+
else
49+
{
50+
GetLocalCopyVariableNameFromUser();
51+
}
52+
4453

4554
if (!IsCancelled)
4655
{
@@ -50,13 +59,6 @@ public override void Fix()
5059

5160
private void GetLocalCopyVariableNameFromUser()
5261
{
53-
if (_forceUseOfSuggestedName)
54-
{
55-
_localCopyVariableName = AutoSuggestedName();
56-
IsCancelled = false;
57-
return;
58-
}
59-
6062
using (var view = new AssignedByValParameterQuickFixDialog(_originalCodeLines))
6163
{
6264
view.Target = _target;
@@ -139,7 +141,6 @@ private string[] GetMethodLines()
139141
{
140142
int zbIndex; //zero-based index
141143
zbIndex = Selection.Selection.StartLine - 1;
142-
//int startLine = Selection.Selection.StartLine;
143144
string[] allLines = GetModuleLines();
144145

145146
string endStatement = GetEndOfScopeStatementForDeclaration(allLines[zbIndex]);

0 commit comments

Comments
 (0)