Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8861119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:25:14+00:00 2026-06-14T15:25:14+00:00

I have a fairly complex thing stuffed into a T4 template. Basically I take

  • 0

I have a fairly complex thing stuffed into a T4 template. Basically I take something like

{=foo=} more text…

and convert it into a class(view) like so:

public class MyView
{
  public string foo{get;set;}
  public string Write()
  {
    return foo+@" more text...";
  }
}

The code generated is of course much more complicated than this. Anyway, the T4 template is over 600 lines of code right now and really becoming unmanageable fast. I believe the main problem is mixing code and “content”(ie, static code). I’m not really sure how to cleanly fix this problem though(while of course not affecting the code generated). I also don’t see any feasible way to unit test my T4 code, other than simply testing it for T4 execution errors. And of course there seems to be the nearly impossible task of testing it’s generated code.

Are there any “model-view” type frameworks or techniques I can use to make my T4 template code more clean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:25:15+00:00Added an answer on June 14, 2026 at 3:25 pm

    After a long journey, I finally checked in the first unit tests to my T4 templates. Basically, what I did was abstract out a “view” (the actual T4 template), and the “logic” (what generates the code, but doesn’t actually output it and doesn’t rely on T4)

    I then took this a step further and used a big hack to make it so that my logic file compiles outside of T4. This had the nice effect of making it so that intellisense and compiler errors worked. It also let me access my logic class from unit tests by simply referencing the project.

    I wrote an article complete with code examples(before/after) and example unit tests on my blog, if you want the lengthy details on how to do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a fairly complex WordPress + bbPress installation and I would like to
I have a fairly complex OLAP database, which basically amounts to a header record,
I have a fairly complex application which has been broken up into multiple components.
I have a fairly complex model for one of my pages; it's made of
I have a fairly complex set of rewrite rules to give my site pages
I have a fairly complex html form enhanced via jquery. It has multiple tabs,
I have a fairly complex (or ugly depending on how you look at it)
I have a fairly complex data model and consequently a fairly complex query (using
I have a fairly complex view that has multiple forms, lots of validations on
So I have a fairly complex activity the parent being a linearlayout with a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.