Create column headers based on the DisplayName attribute?

When I create a view from a list template, I notice that the column names are not based on the DisplayName () annotation. I know how to edit the list.tt code template, but I have no idea how to get the DisplayName attributes from the class properties.

+1
source share
1 answer

A common way to get the DisplayName attribute is reflection. The problem you are about to have is .tt templates and reflection that do not fit together. Reflection is based on loading code into the AppDomain. Since .tt files do not actually load code, you cannot mirror them.

More on this issue and possible solution:

http://www.olegsych.com/2007/12/how-to-use-t4-to-generate-decorator-classes/

MVC and Visual Studio should use some code checking to generate some part of the generated file, so I would look at this path, maybe some crazy regular expression if you don't solve the reflection problem.

+1
source

Source: https://habr.com/ru/post/910788/


All Articles