生成基于displayName属性columnheaders? [英] Generate columnheaders based on the DisplayName attribute?

查看:132
本文介绍了生成基于displayName属性columnheaders?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我生成列表模板,我注意到列的名称并非基于显示名称()标注的视图。我知道如何编辑list.tt code模板,但我不知道如何检索显示名称从类属性的属性。

When I generate a view from the List template I notice that the names of the columns are not based on the DisplayName() annotation. I know how to edit the list.tt code template but I have no idea how to retrieve the DisplayName attributes from the class properties.

推荐答案

要获得displayName属性的常用方法是通过反射。你将拥有的问题是.TT模板和反射不玩好起来。反射依赖于code被加载到AppDomain中。由于.TT文件不实际负荷code,你不能反映在他们。

The common way to get the DisplayName attribute is via reflection. The issue your going to have is .tt templates and reflection don't play nice together. Reflection relies on code being loaded into the AppDomain. Since .tt files don't actually load code you can't reflect over them.

这个问题,在这里,一个可能的解决方案的更多信息:

More information about this issue, and a possible solution here:

HTTP:// WWW .olegsych.com / 2007/12 /如何使用的-T4到生成,装饰类/

MVC和Visual Studio如果必须使用某种类型的code检查产生一些生成的,所以我会沿着这条道路看起来或许有些疯狂的正则表达式,你不进解决反射问题。

MVC and Visual Studio must use some type of code inspection to generate some of the generated so I'd look along that path, maybe some crazy regex, if your not into solving the reflection issue.

这篇关于生成基于displayName属性columnheaders?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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