This is my first stack overflow quesiton, so if i'm not posting correctly, or not tagging right or whatever, please let me know.
For those curious, at the end of this question is a bit of background of why I want to do this.
I'm hoping someone has some ideas of how I can easily take a code file and then get an array of strings with each array element containing the contents of a single method from that code file.
What I want to do is be able to easily parse a .Net code file into it's indivdial methods. Reading the file from disk is quite simple - parsing so that I have individual strings of each of the methods is what I'm looking for a better method of doing. The code files I will be passing through this are VB, but ideally I'd like to see this working with C# also. For the VB side, cycling through each line looking for the keywords of method declaration, then the next instance of the "end sub" and "end function" should work, but that won't easily translate to C#. I also can't get past this feeling there has to be a better way - possibly through reflection.
Now for the background: I have recently found that when windows forms are called with .ShowDialog, the resources aren't cleaned up after your done with the form - you have to specifically dispose of it. This was discovered tracing down memory leaks in an application I work on. So what I need is to track down every instance of where showdialog is called and dispose is not called. A code search shows that I have over 300 instances of showdialog. That's a bit tedious to go through each one, and find if the form is correctly disposed. If I have strings of all of the methods, I can just search for methods that include showdialog and not dispose. This will give me very targeted direction to get these things cleaned up, as well as give me a tool I can run regularly and find anyplace that may have introduced this back into the code.
Sorry for the long winded post here. Any and all suggestions are greatly appreciated.
Don't do this. Look into tools like ReSharper from JetBrains or RefactorPro from DevExpress. These tools are designed to highlight code smells such as undisposed resources along with many many other things. Using one of these tools will be far more helpful to you and help you clean your code up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With