Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Visual-Studio macros , +
Hi All,
 
I have 300 files which having different namespaces,classes etc. Using System.Reflection I made a list of namespaces, classes, classes' data members ,property and methods list. I need to change name of all namespaces, classes, classes' members, methods and properties names. I have also decided future name of namespaces and all other code part. and made a list like (Oldname=>Newname).
 
I come to know that Refactor also supported in "Object Browser" window too. Is there any way that to automate refactor process using Macro?
 
e.g
1) My current selection in object browser is MyNamespace.MyClass. Than go to Refactor->rename, it open refactor dialog. i notice that textbox having name "MyClass"
2) Now i will lookup "MyClass" new name in my list which i have decided, say i found new name "MyNewClass".
3). i will replace MyClass With "MyNewClass" and press OK.
4) than move to next node in object borwser.
 
Is it achievable? I don't know macro programming. Is there any classes/namespaces available to do this task?
 
Thanks
Posted 14-Apr-13 22:12pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Yes, this is achievable, but this is quite a big work. Reflection won't help much, because it works with compiled assemblies or assemblies created during runtime, but refactoring has to work with source code.
 
Is there available classes? It actually depends on available compilers. There are some provisions, but they are not implemented in any of the compilers I knew so far. Here is the idea: the abstract class System.CodeDom.Compiler.CodeDomProvider has the method Parse which could generate a CodeDOM tree instead of compilation. Please see:
http://msdn.microsoft.com/en-us/library/system.codedom.compiler.codedomprovider.aspx[^],
http://msdn.microsoft.com/en-us/library/system.codedom.compiler.codedomprovider.parse.aspx[^].
 
It would be a great help. Unfortunately, in all the implementations I knew so far, this method is not supported (throws "not implemented" exception). So, it looks like you don't have anything close from .NET FCL.
 
Of course, you can try to find some 3rd-party products, but this is a different story.
 
—SA
  Permalink  
Comments
Bhavin Jagad at 19-Apr-13 2:52am
   
Hi, I need to do rename my whole solution.
Thus I surfed regarding that and I came to know this can be achieved through macro programming.
I also found some sort of code to do this.
So I have done code as my requirement using the found code.
But when i run this code it gives exception when it is going to call RenameSymbol().
I am new to macro programming. I surfed around to overcome this exception, but still can't get any solution.
Please help.
Below is link of my gist.
 
https://gist.github.com/anonymous/5418569
Bhavin Jagad at 19-Apr-13 3:31am
   
Hi,
In my first gitst, CodeModel is not working so I use another option which FileCodeModel and write another code.
But in this case, I got exception while running macro.
And occurrence of this exception is not fixed. It comes randomly.
I can't figure out the cause of exception as some code is being executed.
Please help.
Below is link of another gist.
 
https://gist.github.com/AnishGhumara/5418693

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

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Maciej Los 250
3 Shweta N Mishra 216
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,665


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 15 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100