如何获得T4在VS2010遍历类的属性 [英] How to get T4 in VS2010 to iterate over class' properties

查看:221
本文介绍了如何获得T4在VS2010遍历类的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Visual Studio 2010,并安装了tangibleT4EditorPlusModellingTools。

I'm using Visual Studio 2010, and have the tangibleT4EditorPlusModellingTools installed.

我只是用T4打转转,有没有碰过它previously。我想要做的就是看我在项目类中的一个,并写出每个属性。

I'm just playing around with T4, having never touched it previously. What I'd like to do is look at one of my classes in the project, and write out each of the properties.

谁能给我绝对的初学者技巧的.TT文件应该如何构建?我GOOGLE了这一点,并没有找到答案,所以任何帮助将是AP preciated。

Could anyone give me absolute beginner tips to how the .tt file should be structured? I've googled this and haven't found an answer, so any help would be appreciated.

感谢。

推荐答案

这是真的很难为T4模板和反射不玩好起来。

This is really hard as T4 templates and reflection don't play nice together.

请参阅我的回答类似的,可能重复,问题在这里:

See my answer to a similar, possible duplicate, question here:

<一个href=\"http://stackoverflow.com/questions/3157577/generate-columnheaders-based-on-the-displayname-attribute/3158701#3158701\">Generate基于displayName属性columnheaders?

更新:

我并不需要检查我的回答,我已经在这条道路,发现反射+ T4模板是有问题的。由其他回答者提供的平庸例子并不反映提问者正试图完成任务的真正复杂性。尝试使用更真实的反映指标,如自定义code,而不是一个.NET类。

I don't need to check my answer, I have gone down this path and found reflection + t4 templates to be problematic. The banal example provided by the other answerer doesn't reflect the true complexity of the task the questioner is trying to accomplish. Try using a more realistic reflection target, like custom code, rather than a .NET class.

之所以在我提供的链接,但因为它的更容易投我失望阅读链接之前,我会在这里发布这清楚地解释:

The reason why is clearly explained in the links I provided but since its easier to vote me down before reading links I'll post this here:

访问.NET元数据的一个明显的第一选择是反思。内置于.NET基础类库,该API提供了访问.NET类型的元数据。不幸的是,反思是为code执行优化。一个特别的限制,使得它不适合为code一代 - 使用反射加载的程序集只能与它的AppDomain被卸载由于T4模板被编译成.NET程序集和缓存,以提高code一代的性能,使用。反射来访问该组件装配导致T4锁定它。更改/重新编译组件,直到关闭并重新打开该解决方案。因为你可以用这个烦恼生活,这将是很好,以避免此prevents你。

这篇关于如何获得T4在VS2010遍历类的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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