As the other answerer said, you can use Ctrl+Shift+H to search and replace across all files, but you'll need some fairly clever regex (regular expressions) to get what you want directly. You would have to set the search-replace to use regular expressions using the checkbox for that. (Don't forget to turn it off afterward if you don't use it regularly.)
In your example, it would be simple to look for
void (\S+)\(\)(\s*){(\r\n\s*)string foo = "bar";
and replace it with something like
void $1()$2{$3string foo = "$1";
Or rather it would be simple if you already know regex. I tried this regex on some of my own code and it worked. However, it gets a lot harder if some methods take parameters and others don't, if some are void
and others return something, if visibility keywords like public
and private
both appear, etc., etc.
So honestly you may just want to bite the bullet and do these in part by hand. You could do searching for signature characteristics (like void
or public
) and hand-edit each instance.
You could also write code that works over your files, but that would certainly take much longer than other options.
BTW there's a function called nameof(…)
that also does this nicely — but you'd still have to identify every place to use it, and it returns runtime values when used, so if names are obfuscated, nameof()
's also should be.
If you search the web for regular expressions for this purpose, you may find something advanced enough to fully suit your search needs. Editing it to do exactly what you need will be a bear unless you know regex or have the time to learn it right now. :-)
Hope this helps!