Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Morning all,

I was just thinking of a quick way to do a repetitive set of steps on c# files, kind of like a macro.

I want to create a method within visual studio 2012 that will allow me to call the following steps.

Remove and organise using statements
Find and replace "this." with ""

And if possible

Remove using statements that are specifically defined, for example

using Point = System.Windows.Point;


Fix missing namespaces after the above step

Any suggestions on the best approach so I am able to start investigating?
Posted
Updated 10-Jan-13 4:47am
v2
Comments
Sergey Alexandrovich Kryukov 10-Jan-13 10:03am    
Unless you clearly explain the ultimate purpose of it, I doubt anyone will volunteer wasting time for this. As I'm not sure if it makes any sense...
—SA
PaulPrice 10-Jan-13 10:25am    
Quite simply I find myself cleaning up an old code base that has a lot (i mean a lot) of redundant statements and using statemebnts that are explicitly decalred as I showed above.

I would like to automate this and would like opionions on possible avenues I can investigate. Not full answers as to how to do it.

Does that make sense?
Sergey Alexandrovich Kryukov 10-Jan-13 11:17am    
You see, this is a pretty modest task. If you want to develop a whole Visual Studio add-on, which is not a very simple task, will it justify all the effort? It it will, just go ahead with Visual Studio add-ons; developing of which is well documented...
A macro? (Sigh...)
—SA
Richard MacCutchan 10-Jan-13 11:08am    
I only have the Express editions of VS, but in a previous life I used the pro edition and it allowed you to create (record) and run macros. It should be a fairly simple matter to create a macro that does find and replace for most of the specific cases you have in mind.

1 solution

I don't know of any tool which will do that for you - I would suggest that it might be best to write an application to do it outside of VS.

However, I would exercise extreme caution with the "this." removal - I know why you want to, and I agree it is both ugly and unnecessary. But... There are cases when you need it:
public int Lines { get; set;}
public MyClass(int Lines)
   {
   this.Lines = Lines + 10;
   }
Without the "this." part the code fails to initialize the property.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900