Click here to Skip to main content
15,744,010 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?

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?


1 solution

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:[^],[^].

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.

Share this answer
Bhavin Jagad 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.
Bhavin Jagad 19-Apr-13 3:31am    
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.

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