This is really hard as T4 templates and reflection don't play nice together.
See my answer to a similar, possible duplicate, question here:
Generate columnheaders based on the DisplayName attribute?
Update:
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:
"An obvious first choice for accessing .NET metadata is Reflection. Built into .NET base class library, this API provides access to metadata of .NET types. Unfortunately, Reflection is optimized for code execution. One particular limitation makes it ill-suited for code generation - an assembly loaded using Reflection can only be unloaded with its AppDomain. Because T4 templates are compiled into .NET assemblies and cached to improve performance of code generation, using Reflection to access the component assembly causes T4 to lock it. This prevents you from changing/recompiling the component until you close and reopen the solution. While you can certainly live with this annoyance, it would be nice to avoid it."