在C#(Visual Studio)的给定解决方案中,我需要检测一些模板后面的类并提取该模板以便以后生成代码。
换句话说,我需要比较2个类(文件)并从中提取一个通用模板。 当程序员必须编写更少的代码时,该模板将用于以后的代码生成。
是否有任何机构可以让我知道如何做到这一点?
还有一个问题,是否有可能获得Visual Studio制作的语法/语义树?
TNX
On a giving solution in C# (Visual Studio), I need to detect classes that follows some template and extract that template for later code generation.
In other words, I need to compare 2 classes (files) and extract a common template from them. This template will be used for a later code-generation, when the programmer will have to write less code.
Is there any body who can give me an idea on how to do this ?
One more question, is there possible to get the syntactic/semantic tree made by Visual Studio ?
Tnx
最满意答案
对于第一个问题,我认为你应该研究diff算法来找到2个文本文件的公共部分,例如这里 。
对于第二个问题,我建议你去看看罗斯林
Finally I user
NRefactory for compiling code and I obtained the AST. rewrite the code using custom labels (eq: for --> loop_start ) flatten the tree obtaining a long label array (eq: class_start, method_start,...end, end ) this was for 2 files I compared the 2 arrays using "greedy string tiling algorithm" and from here I already had the templates files.更多推荐
发布评论