本文介绍了使用T4(文本转换模板工具包)生成运行时文本/代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是b $ b $
我一直在寻找一个很好的例子,说明如何在运行时使用T4从我的C#程序提供的字符串生成文本文件或数据库。  
$


我打算这样做是为了在运行时以HTML格式生成部分用户界面。



我希望我可能有很多(1,000 +)个模板,我们需要在没有重新编译/重新安装的情况下添加到模板中。



全部到目前为止我找到的完整示例是用于在构建时生成代码或者是非常不完整的运行时示例。



第二个相关问题是,T4是否正确工作的工具?

T4如此专注于构建时间生成,我最好还是使用另一个模板引擎?
b $ b b如果是这样,你有什么建议?

到目前为止,我看过:http://www.stringtemplate.org/和http://csharp-source.net/open-source/template-engines

我我希望在可预见的将来,所有模板都将由我自己或其他程序员编写。  但是将来我们可能希望让最终用户编写模板。  如果我们这样做,我觉得T4可能不是最好的工具?



非常感谢提前。

Pi



Pi

解决方案

Hi Everybody,

I have been searching for a good example on how to use T4 at runtime to generate text from a string that my C# program has supplied from a file or database.  

What I am intending this for is to generate parts of the user interface in HTML at run time.

I am expecting that I may have many (1,000+) templates and we will need to add to the templates without a recompile / reinstall.

All of the complete examples that I have found so far are for generating code at build time or are very incomplete run time examples.

A second related question is, is T4 the right tool for the job?
T4 is so focused on build time generation, would I be better off using another template engine?
If so, what are your recommendations?
So far I have looked at: http://www.stringtemplate.org/ and http://csharp-source.net/open-source/template-engines
I am expecting that for the foreseeable future all of the templates will be written by myself or one of the other programmers.  But in the future we may want to let end users write templates.  If we do that, I feel that T4 may not be the best tool?

Many thanks in advance.
Pi


Pi

解决方案


这篇关于使用T4(文本转换模板工具包)生成运行时文本/代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 05:39