Recently, I learnt how to generate code using T4 text templates. The requirement was to read data from a CSV file and create in-memory objects based on the data representation in the CSV file. So if my CSV file had records with 4 columns, the code had to read the file and create in-memory objects such that each object has 4 fields mapped to the 4 columns. There were multiple CSV files of different record types and manually creating a class for each record type was tedious. After doing commonality/variability analysis, it was apparent that I could use T4 to generate the CSV file reader for each record type by reading metadata about the CSV file.
As my understanding of T4 evolves, I will share my learning here. For reference, posting some good links that provide some guidelines on code generation and when to use it.
Code Generation good or evil
Code Generation Pros and Cons of T4 template
MSDN Code Generation and T4 templates
Subscribe to:
Post Comments (Atom)
What is success?
The journey of life takes us through varied experiences like landing an admission at a prestigious college, earning a degree, getting hired,...
-
Recently after a domain password change, I got the following error in trying to run the webrole. Can not log on locally to WebRole as us...
-
I was trying my hands at creating a .NET 2.0 component that can be consumed by a COM application. One of the errors I got in the process of...
-
After editing the post-build event of my project in VS 2005, the following error came up "'Exec' task needs a command to execut...
No comments:
Post a Comment