T4 混乱
我认为我了解 T4 的基本原理,但我很难弄清楚如何将其应用于我的特定情况。
我有一个显示某种对象列表的应用程序 - 不管是什么。 我希望允许用户选择 1 个或多个这些对象并将它们提交到任何模板。 例如,该模板可以生成一个描述对象的 html 文件或一个 powershell 脚本来以某种方式或其他方式操作它们。
我不明白的是如何将选定的对象传递到我的自定义主机中。
我可以创建一个广泛的 tt 包含文件,该文件调用我自己的 api 来从其存储中检索这些对象,但是当我已经在范围内拥有对象的实例并且我只想检查它们以生成一些文本输出时,这似乎很愚蠢。
我希望这是有道理的...
我尝试向我的主机添加属性,然后使用特定于主机的设置我认为我可以通过这些属性使用对象,但我得到的只是有关序列化和此类内容的错误。
如果有一个很好的例子来说明如何做到这一点那就太棒了:)
谢谢
I think I understand the basic principals of T4 but I'm having a hard time figuring out how to apply it to my particular situation.
I have an application that display lists of objects of some kind - doesn't matter what. I want to allow the users to select 1 or more of these objects and submit them to any template. The template could generate, for example, an html file describing the objects or a powershell script to manipulate them in some way or whatever.
The thing I cant figure out is how to pass the selected objects into my custom host.
I could create an extensive tt include file that called my own api to retrieve these objects from their storage, but this seems silly when I already have instances of the objects in scope and I just want to examine them to produce some text output.
I hope this makes sense...
I have tried adding properties to my host and then using the hostspecific setting I thought I could use the objects via these properties but all I get is errors about serialization and such stuff.
A really good example of how to do this would be fantastic :)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这篇文章会回答您的问题。 “独立模板”可能是最好的设计选择。 其他选项是环境变量和外部文件。 但是,我希望您决定不使用自定义主机(除非您想要拥有自己独特的 T4 风格,可能与任何其他 T4 主机不兼容)并改用 TextTransform.exe。
Perhaps this article will answer your question. "Standalone Template" may be the best design option. Other options are environment variables and external files. However, I hope you decide against using a custom host (unless you want to have your own, unique flavor of T4, likely incompatible with any other T4 host out there) and use TextTransform.exe instead.