T4模板拦截

发布于 2024-10-07 17:44:47 字数 332 浏览 0 评论 0原文

我想知道是否有人知道基于 T4 模板的方法拦截系统?

我们开始编写移动应用程序(目前使用 iOS 版 MonoTouch)。我们有一套非常好的 DI/IoC 核心功能,我想在新平台的开发中利用它。由于不支持运行时代码生成Reflection.Emit,我希望使用T4模板来实现动态拦截功能(+ TinyIoC作为解析的容器)。

我们目前正在使用 Castle Windsor(并打算继续为我们的 SL 和完整的 .NET 开发这样做),但是所有 Windsor 特定关系都被完全封装,因此如果有合适的 T4 解决方案,那么实现一个合适的 T4 解决方案应该不难。使用基于 T4 的实现而不是 Windsor 的适配器。

I'm wondering if anyone out there knows of any T4 template based method interception systems?

We are beginning to write mobile applications (currently with MonoTouch for IOS). We have a very nice core set of DI/IoC functionality and I'd like to leverage this in development for the new platform. Since runtime code generation Reflection.Emit is not supported, I'm hoping to use T4 templates to implement the dynamic interception functionality (+ TinyIoC as a container for resolution).

We are currently using Castle Windsor (and intend to continue doing so for our SL and full .NET development), but all of the Windsor specific ties are completely encapsulated, so given a suitable T4 solution, it shouldn't be hard to implement an adapter that uses a T4 based implementation instead of Windsor.

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

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

发布评论

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

评论(1

套路撩心 2024-10-14 17:44:47

如果我理解正确的话,您想使用 T4 动态生成代码(在运行时)。我不知道有任何系统可以做到这一点,但我认为编写这样的东西并不难。

您需要做的是指示 C#(或任何其他 .NET 编译器)编译一些代码并生成程序集。完成后,您需要将此程序集加载到您的 AppDomain 中。之后,您可以使用动态加载的程序集中的类型。

T4 模板引擎是(如果我没记错的话)Visual Studio 的一部分,因此困难的部分是指示模板引擎生成代码,可能您的应用程序不需要依赖于 Visual Studio 甚至启动它(那太糟糕了)。

如果您不需要 T4 的全部功能(这很可能),您也可以自己生成一些 .NET 代码,将其保存到文件中并指示 C# 编译器为您生成程序集。

祝你好运。

If I understand correctly you want to use T4 to generate code on the fly (at runtime). I'm not aware of any system that does this, but I don't think it would be very hard to write such a thing.

What you need to do is instruct the C# (or any other .NET compiler) to compile some code and generate an assembly. When this is done, you need to load this assembly into your AppDomain. After that you can use the types in that dynamically loaded assembly.

The T4 template engine is (if I'm not mistaken) part of Visual Studio so the hard part will be to instruct the template engine to generate the code, possibly without your application to need a dependency on Visual Studio or to even start it (that would be awful).

If you don't need the full capabilities of T4 (which is likely) you could also spit out some .NET code yourself, safe it to a file and instruct the C# compiler to generate an assembly for you.

Good luck.

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