自动质量重构整个项目代码 [英] Automated Mass refactor whole project code

查看:87
本文介绍了自动质量重构整个项目代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有300个文件,它们有不同的名称空间,类等。使用System.Reflection我创建了一个名称空间,类,类列表''数据成员,属性和方法列表。我需要更改所有名称空间,类,类的成员,方法和属性名称的名称。我还决定了名称空间的未来名称和所有其他代码部分。并制作了一个像(Oldname => Newname)这样的列表。



我知道Refactor也支持对象浏览器窗口。有没有办法使用Macro自动化重构过程?



例如

1)我在对象浏览器中的当前选择是MyNamespace.MyClass。然后去Refactor->重命名,它打开重构对话框。我注意到文本框的名称为MyClass

2)现在我将在我的列表中查找MyClass新名称,我已经决定,我发现新名称为MyNewClass。

3)。我将用MyNewClass替换MyClass并按OK。

4)而不是移动到对象borwser中的下一个节点。



可以实现吗?我不知道宏编程。是否有可用于执行此任务的类/命名空间?



谢谢

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

推荐答案

是的,这是可以实现,但这是一项相当大的工作。反射不会有多大帮助,因为它适用于在运行时创建的已编译程序集或程序集,但重构必须使用源代码。



是否有可用的类?它实际上取决于可用的编译器。有一些规定,但到目前为止我所知道的任何编译器都没有实现它们。这是一个想法:抽象类 System.CodeDom.Compiler.CodeDomProvider 具有方法 Parse ,它可以生成CodeDOM树而不是编译。请参阅:

http://msdn.microsoft .com / zh-cn / library / system.codedom.compiler.codedomprovider.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.codedom.compiler.codedomprovider.parse.aspx [ ^ ]。



这将是一个很好的帮助。不幸的是,在我目前所知的所有实现中,不支持此方法(抛出未实现异常)。所以,看起来你没有接近.NET FCL的任何东西。



当然,你可以尝试找到一些3 rd -party产品,但这是一个不同的故事。



-SA
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


这篇关于自动质量重构整个项目代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆