GetReplacementLine()
Instead of using String.Replace()
you should check out the TokenRewriteStream
mentioned in this answeranswer.
If you need to use String.Replace()
then you should omit the not needed call to String.Contains()
. If the string which should be replaced isn't found in the 'content', the unchanged 'content' will be returned. In addition it will speed up the execution because it does not have to search for the token twice.
But you also have duplicated code inside this method, so it would be better to extract this into 2 separate methods. One replacing the searchterm with a passed prefix and the other with a passed postfix.
Like:
private string PostfixReplace(string content, string token, string newName, string postFix)
{
return content.Replace(token + postFix, newName + postFix);
}
AcquireTarget()
There is no need to call ToList()
on the result of the Linq Where
clauses because you only need either First()
or FirstOrDefault()
. The call to ToList()
will slow down the execution because every item will be qualified but you only need the first one.
var
IMHO you are misusing the var
keyword, because you use it all the time. Assume you need to dig into this class after not touching it for a few weeks, you won't know what most of the types will be, because it isn't obvious what type the right side is, e.g
var targets = _declarations.Items.Where(declaration => declaration.QualifiedName.QualifiedModuleName == selection.QualifiedName && (declaration.Selection.Contains(selection.Selection)) || declaration.References.Any(r => r.Selection.Contains(selection.Selection))) .ToList();