Unused procedures vanish automatically on compile.
When I compile or debug the program I want all unused procedures to vanish automatically. (example: Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged End Sub should vanish when debug/compile if no code is inside it.)
This worked in VB6.
Thanks for taking the time to share this suggestion. This item has been around for a couple of versions of Visual Studio and we haven’t acted on it. Looking at the VS “15” plans, we’re not going to take action on this item, so we’re going to close it. If the suggestion is still relevant, please either take a look to see if there’s another suggestion that’s similar that you can vote on, or open a new suggestion.
- The Visual Studio Team
Real VB6 programming and VBA programming commented
Lots of things worked in the VB6 programming language that don't work in .Net.
David Nuttall commented
I like this feature of VB6 and I would support it in VB.Net, but I would want it as an option set in the Project properties, probably under Compile options, and set to off when the Project is created.
Delete Unused Procedures: [check-box, default off]
If a Sub or Function is empty (definition, chunk of white-space, End Sub) it qualifies for removal. Putting a comment in it (or anything else) will keep it from getting removed during compile.
Lucian Wischik commented
If you use ProjectN, then this "dead-code-removal" happens automatically.
But in general it's a scary thought because it would break reflection. In general the compiler has no way of knowing whether a member will be invoked by reflection or not. (ProjectN works by making a guess at where you will want to use reflection, but letting you tweak it further).
Adorian Doran commented
The idea is actually not bad. I like it! I use to do reusable code, that may contain features that may not be used in a certain project. It would be nice for these methods/fields to get discarded at compile time, if they are marked as dispensable through an attribute and are not called nor members of an interface or base class.
Mr. VB6 commented
In VB6, default unused procedures do that, and that is smart! if you rename the default procedure, then it does not disappear :)
To Draco - Wy on earth do you want to keep empty procedures - which was created automatically by the IDE? If you dont use them by putting code inte them - why keep them?
Draco Paladine commented
Absolutely NO, this would break a number of interface requirements.
Only empty sub procedures which are automatically created by the IDE should vanish (just like in VB6). If you doubleclick on control but don't put any code into the new procedure it should vanish automatically on compile.
Marc Johnston commented
no vote ... you got to be kidding
Nick Roberts commented
Maybe it should be a specific refactoring option, which can be applied to a whole project as well as to a specific class (or file)?
It could be counteracted in a specific procedure by putting a comment in it? (E.g. a TODO.)
My intention is thas only empty sub procedures which are automatically created by the IDE, when you double click on a control, are going to be removed. On VB6 this type of sub procedures vanish when you run a full debug - and manually created sub procedures are left unchanged. This is exactly the way I want it.
As long as it's optional! Are we talking about deleting such out of source, or simply not including it in compile/debug? I can't be the only one who often has empty procedure stubs here and there, waiting to get either fleshed out or [manually] deleted.