.NET
  Home arrow .NET arrow Page 19 - Outputting Code
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Outputting Code
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 5
    2004-10-04

    Table of Contents:
  • Outputting Code
  • Understanding Script Directives
  • Understanding Other Features of the Generation Harness
  • Extending the Harness
  • Examining Code Generation Mechanics
  • Exploring Details of XSLT Code Generation
  • Creating Named Templates
  • Creating Match Templates
  • Supporting Stylesheets
  • Exploring Details of Brute-Force Generation
  • Creating a Class
  • Creating the Support Template
  • Understanding Types
  • Building a CodeDOM Graph
  • Building the Code Structure
  • Outputting Assignments
  • Creating Arrays
  • Exploring Other Features
  • Working with the CodeDOM

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Outputting Code - Working with the CodeDOM


    (Page 19 of 19 )

    I’ve just fluttered over the top of the CodeDOM, focusing on what it means to work with code as an abstract language-independent entity. Although this may seem natural to you if you took a compiler course, it’s a different way of looking at code than day-to-day creation in one or a small number of languages. Appendix D covers additional issues, incompatibilities, and limitations of the CodeDOM.

    Most of the tips for efficient use of brute-force generation apply to the CodeDOM. You can’t output regions without snippets, so you may want to replace regions with comments; however, you’ll still want segments of your code output by individual methods. To maintain language neutrality in the CodeDOM, do the following:

    • Avoid using snippets.

    • Test your ability to compile the output in all target languages early and often.

    • Test your component or application in all target languages.

    • If you can’t follow the first tip, provide alternate code for all target lan guages and re-create the CodeDOM graph for each language.

    If nothing else, you can hand this second part of this chapter to your boss if she thinks you should use the CodeDOM. Comparing these three methods of code generation illustrates just how expensive CodeDOM is for developing applications.

    Summary

    One-click code generation allows anyone to precisely regenerate your code now and in the future. Reproducible one-click generation relies on a script. The script used in this chapter is a set of XML directives.

    The keys to success for XSLT code generation are as follows:

    • A single entry-level template accessing the root.

    • A single high-level processing template called in the context you’re processing.

    • A named template for each region in the output after you organize your sample code into regions.

    • Adding nested named and match templates while regions become longer and more complex.

    • Using match templates for any looping elements unless the output is nearly trivial.

    • A separate supporting stylesheet to contain reusable utility templates. The keys to success for brute-force code generation are as follows:

    • Break metadata extraction away from code outputting.

    • Split outputting into individual classes that each output a single file pattern.

    • Within each class, use an entry-level method.

    • Use a different method for each region.

    • Use additional methods while regions become longer and more complex.

    • Use supporting methods for reuse wherever possible.

    The CodeDOM abstracts your code sufficiently to generate code in any one of several languages. This abstraction makes working with the CodeDOM extremely complex. Seriously evaluate whether the extra time involved in working with the CodeDOM is justified for your application.

    Additional Reading

    To find more information about the topics covered, try the following resources:

    This chapter is from Code Generation in Microsoft .NET by Kathleen Dollard (Apress, 2004, ISBN: 1590591372). Check it out at your favorite bookstore today.

    Buy this book now.

     


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    .NET ARTICLES

    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...
    - Creating Summary .Net Crystal Reports
    - More on Commands, Input and the WPF





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    Stay green...Green IT