Your SlideShare is downloading. ×
0
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Code Generation using T4
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Code Generation using T4

2,806

Published on

Text Template Transformation Toolkit

Text Template Transformation Toolkit

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,806
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Code Generation using T4
    Joubin Najmaie
    Software Architect @ Softchoice
    Twitter: @joubin
    Personal blog: http://joubin.ca
    http://www.softchoice.com
  • 2. T4 - Agenda
    The “suit” story
    Demo
    T4 Overview
    T4 Syntax
    Demo
    More demos
  • 3. A “suit” calls a meeting
    Empower the business users
    Give control over their content
  • 4. Run back to your desk
  • 5. Site Content analysis
  • 6. Architecting a solution
    Define content type descriptions etc.
  • 7. You start coding away
  • 8. Soon you’ll realize …
    Every time you add a content type
    Data Access Layer code
  • 9. Introducing T4
  • 10. What T4 is not?
  • 11. What is T4?
    T4 is a vehicle
    Generates code from described models
    Models could be
    Visual
    Class diagrams
    ERDs
    Text-based
    XSD
    Database
    Metadata
  • 12. What is T4? (cont.)
    A set of tools to build other tools
    Describe
    Domain Model
    User interface
    Business process
    Flow
    Generate code from model
    Use T4 to generate code
  • 13. T4 - the what
    What does it stand for?
    What are the Inputs?
    What are the outputs?
    What does the syntax look like?
    What are the supported languages?
  • 14. Current usages of T4 in VS.NET
    ASP.NET MVC Views
    Entity Framework 4 model generation
    VS Project templates
    VS Item templates
    Web forms
    Class
  • 15. T4 - Syntax
    A quick overview of T4 syntax
    Lots of demos
  • 16. Anatomy of T4 templates
  • 17. Text Templating
    Write a text template
    T4 engine generates a compiled intermediary class
    T4 engine executes the compiled class to generate output
  • 18. Text Templating
  • 19. Processing Directives
    Similar to ASPX and ASCX
    <#@ and end with #>
    Directives
    template
    assembly
    import
    output
    include
  • 20. template directive
    <#@ template debug="true" language="C#" #>
    Parameters
    debug
    language
    inherits
    hostspecific
  • 21. template directive parameters
    debug parameter
    System %TEMP% folder
    language parameter
    Values: C#, VB, C#3.5
    inherits parameter
    Tells which base class to use
    hostspecific parameter
    A reference to the object that the hosts the engine.
    e.g. Host.TemplateFile
    Host.StandardAssemblyReferences
  • 22. assembly directive
    <#@ assembly #>
    Parameter
    name
    could be an assembly in the GAC
    <#@ assembly name=“System.Data” #>
    or absolute path to the assembly
    <#@ assembly name=“c:projectsproj1indebugproj1.dll” #>
  • 23. import directive
    <#@ import #>
    Parameter
    namespace
    <#@ import namespace=“System.Collections.Generic” #>
  • 24. include directive
    <#@ include #>
    Parameter
    file
    <#@ include file=“includefile.tt” #>
  • 25. T4 Blocks
    Text blocks
    Code blocks
    Statement blocks
    Expression blocks
    Class feature blocks
  • 26. Text blocks
    Non-programmatic text
  • 27. Text blocks - Syntax
  • 28. Statement blocks
    Delineated using
    <# #>
  • 29. Statement blocks - Syntax
  • 30. Expression blocks
    Delineated using
    <#= #>
  • 31. Expression blocks - Syntax
  • 32. Class feature blocks
    <#+ #>
    Used to add any class level construct
    Helper functions
    Fields
    Constants
    Properties
  • 33. Class feature blocks - Syntax
  • 34. Custom Text Template Host
    When would you write one?
    Want to run T4 templates outside of VS.NET
    Integrate functionality into custom tools
  • 35. Code generation
  • 36. VS.NET Item template
    Single file versus multi-file templates
    As .vsi/.zip
    VS 2010
    /{vs.net folder}/common7/ide/itemtemplates
    Template parameters are special params
    When the template wizard runs they are replaced.
  • 37. Parameters
  • 38. Multi-file item template
  • 39. T4 editors in VS.NET
    Plug-in by Tangible Engineering *
    http://visualstudiogallery.msdn.microsoft.com/en-us/60297607-5fd4-4da4-97e1-3715e90c1a23
    T4 Editor by Clarius
    http://www.visualt4.com/downloads.html
  • 40. Slides will be on blog
    http://joubin.ca
    CodePlex project
    http://codekindler.codeplex.com
    Provides boilerplate classes using T4
    Only a few at the moment
    Thank You!
  • 41. Thanks to our contributors

×