如何使用NET反射用T4? [英] How do you use .net Reflection with T4?

查看:218
本文介绍了如何使用NET反射用T4?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#项目,该项目包括一个文本模板。我想这个模板来生成基于对反映在项目中的C#类的一些SQL。

如何使用一个访问当前项目的内容,T4?是有可能的,如果是这样,反射可用,或者是它的访问只是然后必须解析原始资源?

在此先感谢!

解决方案
  

如何一次访问使用T4当前项目的内容是什么?

的一种方法是使用EnvDTE COM组件。谷歌搜索T4和EnvDTE应带回大量的例子。

  

是否有可能的,如果是这样,反射可用,或者是它的访问   只是必须然后解析原始的源?

反思是绝对可以从T4。它的工作原理主要是你所期望的。

奥列格Sych发表有很多关于共同T4的使用场景伟大的博客条目,但也有很多其他的为T4资源在那里。

I have a c# project which includes a Text Template. I would like this template to generate some SQL based on reflecting against the C# classes in the project.

How does one access the current project's contents using T4? Is it possible, and if so, is Reflection available, or is it access to just the raw source that must then be parsed?

Thanks in advance!

解决方案

How does one access the current project's contents using T4?

One way is to use the EnvDTE COM component. Googling T4 and EnvDTE should bring back plenty of examples.

Is it possible, and if so, is Reflection available, or is it access to just the raw source that must then be parsed?

Reflection is definitely available from T4. It works mostly as you would expect.

Oleg Sych has a number of great blog entries regarding common T4 usage scenarios, but there are plenty of other resources for T4 out there as well.

这篇关于如何使用NET反射用T4?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆