Skip to content

Commit ca691d5

Browse files
committed
Remove some more dynamic
1 parent 1c7ea1e commit ca691d5

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

Rubberduck.Core/Navigation/RegexSearchReplace/RegexSearchReplace.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Text.RegularExpressions;
5+
using Antlr4.Runtime;
56
using Rubberduck.Common;
67
using Rubberduck.Parsing;
78
using Rubberduck.Parsing.Symbols;
@@ -137,7 +138,15 @@ private List<RegexSearchResult> SearchCurrentBlock(string searchPattern)
137138
var results = GetResultsFromModule(module, searchPattern);
138139

139140
var qualifiedSelection = pane.GetQualifiedSelection();
140-
dynamic block = state.AllDeclarations.FindTarget(qualifiedSelection.Value, declarationTypes).Context
141+
142+
if (!qualifiedSelection.HasValue)
143+
{
144+
return new List<RegexSearchResult>();
145+
}
146+
147+
var block = (ParserRuleContext)state.AllDeclarations
148+
.FindTarget(qualifiedSelection.Value, declarationTypes)
149+
.Context
141150
.Parent;
142151
var selection = new Selection(block.Start.Line, block.Start.Column, block.Stop.Line,
143152
block.Stop.Column);

Rubberduck.Refactorings/Common/DeclarationExtensions.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Diagnostics.CodeAnalysis;
55
using System.Globalization;
66
using System.Linq;
7+
using Antlr4.Runtime;
78
using Rubberduck.Parsing;
89
using Rubberduck.Parsing.Grammar;
910
using Rubberduck.Parsing.Symbols;
@@ -423,20 +424,14 @@ public static Declaration FindTarget(this IEnumerable<Declaration> declarations,
423424

424425
foreach (var reference in declaration.References)
425426
{
426-
var proc = (dynamic)reference.Context.Parent;
427+
var proc = (ParserRuleContext)reference.Context.Parent;
427428
var paramList = proc ;
428429

429-
// This is to prevent throws when this statement fails:
430-
// (VBAParser.ArgsCallContext)proc.argsCall();
431-
var method = ((Type) proc.GetType()).GetMethod("argsCall");
432-
if (method != null)
430+
if (paramList == null)
433431
{
434-
try { paramList = method.Invoke(proc, null); }
435-
catch { continue; }
432+
continue;
436433
}
437434

438-
if (paramList == null) { continue; }
439-
440435
activeSelection = new Selection(paramList.Start.Line,
441436
paramList.Start.Column,
442437
paramList.Stop.Line,

0 commit comments

Comments
 (0)