Visual Studio 2010Effective Code Generation Techniques<br />Doug Holland<br />doug.holland@microsoft.com<br />blogs.msdn.c...
Doug Holland<br />Sr. Architect Evangelist, Microsoft Corporation<br />MSc Software Engineering, Oxford University<br />  ...
Agenda<br />StringBuilder<br />System.CodeDom<br />Code Snippets<br />XSLT<br />Visual Studio 2010 Project & Item Template...
StringBuilder<br />Advantages<br />Almost all .net developers should feel comfortable using the StringBuilder class so it ...
System.CodeDom<br />Advantages<br />Allows  a single “template” to generate code within several target languages, such as ...
Code Snippets<br />Advantages<br />Simple Xml based template with numerous samples provided within Visual Studio.<br />Sev...
XSLT<br />Advantages<br />Xml based template.<br />Simple code generation technique for those developers comfortable with ...
Visual Studio Project / Item Templates<br />Advantages<br />Target language used to write the templates. (e.g. C# or VB).<...
T4 Templates<br />Advantages<br />Ability to embed C# control logic within the template.<br />Syntax that will be somewhat...
Unit Testing<br />Should we use unit testing for generated code?<br />
Thank you<br />doug.holland@microsoft.com<br />blogs.msdn.com/dohollan<br />© 2009 Microsoft Corporation. All rights reser...
Upcoming SlideShare
Loading in …5
×

Code generation

608 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
608
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Code generation

  1. 1. Visual Studio 2010Effective Code Generation Techniques<br />Doug Holland<br />doug.holland@microsoft.com<br />blogs.msdn.com/dohollan<br />
  2. 2. Doug Holland<br />Sr. Architect Evangelist, Microsoft Corporation<br />MSc Software Engineering, Oxford University<br /> @dougholland<br />http://blogs.msdn.com/dohollan<br />
  3. 3.
  4. 4. Agenda<br />StringBuilder<br />System.CodeDom<br />Code Snippets<br />XSLT<br />Visual Studio 2010 Project & Item Templates<br />Text Template Transformation Toolkit (T4)<br />Entity Framework 4.0 & T4 Templates<br />UML & T4 Templates<br />SQL Server 2008 R2 Management Objects (SMO)<br />Unit Testing<br />
  5. 5. StringBuilder<br />Advantages<br />Almost all .net developers should feel comfortable using the StringBuilder class so it requires no additional languages / tools to learn.<br />Even with the disadvantages, the StringBuilder can be an excellent choice if you need to generate code quickly. Especially if you don’t need to maintain the “template” long term.<br />Disadvantages<br />Unable to truly see the “template” within the control logic.<br />Requires a recompile if the “template” should be changed.<br />
  6. 6. System.CodeDom<br />Advantages<br />Allows a single “template” to generate code within several target languages, such as VB and C#.<br />Additional language providers can be written to support other languages.<br />Proven technology, used by Microsoft for code generation in all versions of Visual Studio since .net was released.<br />Disadvantages<br />Unable to truly see the “template” within the control logic.<br />Requires a recompile if the “template” should be changed.<br />Very few developers have experience using the CodeDom even though it has been with us since the .net framework 1.0.<br />
  7. 7. Code Snippets<br />Advantages<br />Simple Xml based template with numerous samples provided within Visual Studio.<br />Several open source code snippet libraries available.<br />Disadvantages<br />Limited snippet functions and at the present time developers are unable to author additional snippet functions! <br />Tell the Visual Studio team you want to be able to author snippet functions, tell your Congressman too if you think it would help!<br />
  8. 8. XSLT<br />Advantages<br />Xml based template.<br />Simple code generation technique for those developers comfortable with XSLT transformations.<br />Disadvantages<br />While Xml is a relatively simple technology, XSLT has been known to bring grown men to tears!<br />XSLT can be difficult to debug.<br />
  9. 9. Visual Studio Project / Item Templates<br />Advantages<br />Target language used to write the templates. (e.g. C# or VB).<br />Simple Xml *.vstemplate file tells Visual Studio what to do with the template.<br />Templates are stored within .zip file which is a standard file format we’re all familiar with.<br />Disadvantages<br />Templates are stored within .zip file which can complicate editing templates.<br />
  10. 10. T4 Templates<br />Advantages<br />Ability to embed C# control logic within the template.<br />Syntax that will be somewhat familiar to classic ASP developers..<br />Preferred code generation technique for Entity Framework 4.0 and the Visual Studio 2010 modeling tools., which means lots of samples on MSDN, etc.<br />Templates can be precompiled.<br />Disadvantages<br />While third parties have written language support for Visual Studio no built in support for editing T4 templates exists in Visual Studio today. <br />Tell the Visual Studio product team and your congressman about this too!<br />Relatively new technology, therefore not many developers have experience with T4 templates.<br />
  11. 11. Unit Testing<br />Should we use unit testing for generated code?<br />
  12. 12. Thank you<br />doug.holland@microsoft.com<br />blogs.msdn.com/dohollan<br />© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.<br />The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.<br />

×