从多个文件中提取模板(模式检测)(Extract template from multiple files ( pattern detection ))

编程入门 行业动态 更新时间:2024-10-10 10:26:58
多个文件中提取模板(模式检测)(Extract template from multiple files ( pattern detection ))

在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.

更多推荐

本文发布于:2023-08-03 23:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1404585.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   模板   模式   文件   Extract

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!