I’m currently refactoring an old Visual Basic DLL (VB.Net), which stores all of its data in one module called Globaldefinitions as public fields. There are about 200 fields, referenced thousands of times all around the code:
Public Module Globaldefinitons
Public a As Short
...
Public zz10 As Double
End Module
In the DLL itself, after importing Globaldefinitions, these fields are referenced with their name (No module prefix):
a = 5
I need to change the module into a class with non-shared fields. This means, each and every of these thousands of references needs to reference the instance of that class:
globalDefinitionsInstance.a = 5
How do I go about this efficiently?
Regular expressions operating on the source fall flat. Refactoring tools like Re-Sharper or CodeRush don’t seem to offer this functionality. Visual Studio 2010 cannot do it automatically either.
Here is the way I would go about changing this. For every field in
GlobalDefinitionsdo the followingBad_Name_a. This will turn all of the hard to match names into very easy to match namesBad_Name_atoglobalDefinitionsInstance.Bad_Name_a. No need for even a regex here. The name and replacement are unique