整理 T4 模板

发布于 2024-10-08 06:33:40 字数 251 浏览 7 评论 0原文

我已经开始使用 T4 模板进行一些 DAL 增强。

然而,我发现它们很快就会变得笨拙,并且经常生成格式不良的代码。

我想知道是否有人对组织这些模板以及最后获得良好的格式化代码有任何好的建议。

到目前为止,我的经验是:

  1. 坚持现有已发布模板的功能(例如 SubSonic)
  2. 如果出现缩进,请尝试在最近的 #>
  3. 大量注释后添加一个空行。

I have begun using T4 Templates for a few DAL enhancements.

However, I find they quickly get unwieldy and often produce poorly formatted code.

I am wondering if anyone has any good tips on organising these templates, and on getting great formatted code at the end.

So far my experience is:

  1. Stick to what existing published templates do (e.g. SubSonic)
  2. If indentation is playing up attempt a blank line after the closest #>
  3. Lots of comments.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

简单爱 2024-10-15 06:33:40

将模板拆分为控制/数据准备逻辑和执行输出渲染的“视图”。

首先设置您需要的数据,然后用尽可能少的逻辑编写输出。

如果您可以将输出打包成可重用的块,那么您可以将它们放入方法包装器中的 <#+ #> 中。块并以一组方法调用的形式完成结构工作。

Split your templates into control/data preparation logic and 'views' that do the output rendering.

Set up the data you need first and then write the output with the most minimal logic possible.

If you can parcel up the output into reusable chunks, then you can put those in method wrappers in <#+ #> blocks and do the structural work as a set of method calls.

愛放△進行李 2024-10-15 06:33:40

T4 最终结果缩进

T4 模板将按照模板中的定义格式化代码。缩进如文件本身所定义。为了获得出色的缩进最终结果,T4 模板通常会看起来很奇怪且奇怪的缩进。但代码是有颜色的,所以模板的代码通常就很好。

T4 组织

我通常有一个解决方案文件夹,其中包含所有可重用的 T4 模板(如果有很多模板,也可以将它们放入子文件夹中)。我给他们提供了 ttinclude 文件扩展名。其他的只是包括这些并放在需要的地方。

T4 end result indentation

T4 templates will format code as defined in the template. Indents are as defined in the file itself. To have great indented end result, T4 templates will often look strange and odd indented. But code is coloured so template's code is usually just fine.

T4 organization

I usually have a solution folder with all reusable T4 templates (if lots of them they can be put in subfolders as well). I give them the ttinclude file extension. Others just include these and are put in place where needed.

扭转时空 2024-10-15 06:33:40

使用第三方格式化工具在生成后格式化代码,例如 Teleriks Just Code

Use a third party formatting tool to Format your code after generation like Teleriks Just Code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文