Click here to Skip to main content
15,891,184 members
Articles / Desktop Programming / Windows Forms

Write your own Code Generator or Template Engine in .NET

Rate me:
Please Sign up or sign in to vote.
4.83/5 (64 votes)
26 Sep 20068 min read 259.2K   4.6K   291  
This paper demonstrates building a code generator, template engine, template parser, or template processor in .NET. The demo implementation uses cutting edge .NET technologies available today such as C#, .NET 2.0, MS Provider Pattern, Enterprise Library January 2006, CodeDom etc.
namespace SmartTemplateEngine.WindowsApplication
{
    partial class MainForm
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent( )
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.toolStripButtonNew = new System.Windows.Forms.ToolStripButton();
            this.toolStripButtonOpen = new System.Windows.Forms.ToolStripButton();
            this.toolStripButtonSave = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
            this.toolStripButtonRun = new System.Windows.Forms.ToolStripButton();
            this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator();
            this.toolStripLabelStatus = new System.Windows.Forms.ToolStripLabel();
            this.tabTemplateEngine = new System.Windows.Forms.TabControl();
            this.tabPageTemplate = new System.Windows.Forms.TabPage();
            this.textBoxTemplate = new System.Windows.Forms.TextBox();
            this.tabPageGeneratedCode = new System.Windows.Forms.TabPage();
            this.textBoxGeneratedCode = new System.Windows.Forms.TextBox();
            this.tabPageOutput = new System.Windows.Forms.TabPage();
            this.textBoxOutput = new System.Windows.Forms.TextBox();
            this.tabPageUsingLibraries = new System.Windows.Forms.TabPage();
            this.textBoxUsingLibraries = new System.Windows.Forms.TextBox();
            this.tabPageReferences = new System.Windows.Forms.TabPage();
            this.textBoxReferences = new System.Windows.Forms.TextBox();
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.exitToolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
            this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
            this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
            this.toolStrip1.SuspendLayout();
            this.tabTemplateEngine.SuspendLayout();
            this.tabPageTemplate.SuspendLayout();
            this.tabPageGeneratedCode.SuspendLayout();
            this.tabPageOutput.SuspendLayout();
            this.tabPageUsingLibraries.SuspendLayout();
            this.tabPageReferences.SuspendLayout();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // toolStrip1
            // 
            this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.toolStripButtonNew,
            this.toolStripButtonOpen,
            this.toolStripButtonSave,
            this.toolStripSeparator1,
            this.toolStripButtonRun,
            this.toolStripSeparator2,
            this.toolStripLabelStatus});
            this.toolStrip1.Location = new System.Drawing.Point(0, 24);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new System.Drawing.Size(548, 25);
            this.toolStrip1.TabIndex = 0;
            this.toolStrip1.Text = "toolStrip1";
            // 
            // toolStripButtonNew
            // 
            this.toolStripButtonNew.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripButtonNew.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButtonNew.Image")));
            this.toolStripButtonNew.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButtonNew.Name = "toolStripButtonNew";
            this.toolStripButtonNew.Size = new System.Drawing.Size(23, 22);
            this.toolStripButtonNew.Text = "New";
            this.toolStripButtonNew.Click += new System.EventHandler(this.toolStripButtonNew_Click);
            // 
            // toolStripButtonOpen
            // 
            this.toolStripButtonOpen.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripButtonOpen.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButtonOpen.Image")));
            this.toolStripButtonOpen.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButtonOpen.Name = "toolStripButtonOpen";
            this.toolStripButtonOpen.Size = new System.Drawing.Size(23, 22);
            this.toolStripButtonOpen.Text = "Open";
            this.toolStripButtonOpen.Click += new System.EventHandler(this.toolStripButtonOpen_Click);
            // 
            // toolStripButtonSave
            // 
            this.toolStripButtonSave.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripButtonSave.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButtonSave.Image")));
            this.toolStripButtonSave.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButtonSave.Name = "toolStripButtonSave";
            this.toolStripButtonSave.Size = new System.Drawing.Size(23, 22);
            this.toolStripButtonSave.Text = "Save";
            this.toolStripButtonSave.Click += new System.EventHandler(this.toolStripButtonSave_Click);
            // 
            // toolStripSeparator1
            // 
            this.toolStripSeparator1.Name = "toolStripSeparator1";
            this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
            // 
            // toolStripButtonRun
            // 
            this.toolStripButtonRun.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.toolStripButtonRun.Image = ((System.Drawing.Image)(resources.GetObject("toolStripButtonRun.Image")));
            this.toolStripButtonRun.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.toolStripButtonRun.Name = "toolStripButtonRun";
            this.toolStripButtonRun.Size = new System.Drawing.Size(23, 22);
            this.toolStripButtonRun.Text = "Run";
            this.toolStripButtonRun.Click += new System.EventHandler(this.toolStripButton1_Click);
            // 
            // toolStripSeparator2
            // 
            this.toolStripSeparator2.Name = "toolStripSeparator2";
            this.toolStripSeparator2.Size = new System.Drawing.Size(6, 25);
            // 
            // toolStripLabelStatus
            // 
            this.toolStripLabelStatus.Name = "toolStripLabelStatus";
            this.toolStripLabelStatus.Size = new System.Drawing.Size(0, 22);
            // 
            // tabTemplateEngine
            // 
            this.tabTemplateEngine.Controls.Add(this.tabPageTemplate);
            this.tabTemplateEngine.Controls.Add(this.tabPageGeneratedCode);
            this.tabTemplateEngine.Controls.Add(this.tabPageOutput);
            this.tabTemplateEngine.Controls.Add(this.tabPageUsingLibraries);
            this.tabTemplateEngine.Controls.Add(this.tabPageReferences);
            this.tabTemplateEngine.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabTemplateEngine.Location = new System.Drawing.Point(0, 49);
            this.tabTemplateEngine.Name = "tabTemplateEngine";
            this.tabTemplateEngine.SelectedIndex = 0;
            this.tabTemplateEngine.Size = new System.Drawing.Size(548, 217);
            this.tabTemplateEngine.TabIndex = 1;
            // 
            // tabPageTemplate
            // 
            this.tabPageTemplate.Controls.Add(this.textBoxTemplate);
            this.tabPageTemplate.Location = new System.Drawing.Point(4, 22);
            this.tabPageTemplate.Name = "tabPageTemplate";
            this.tabPageTemplate.Padding = new System.Windows.Forms.Padding(3);
            this.tabPageTemplate.Size = new System.Drawing.Size(540, 191);
            this.tabPageTemplate.TabIndex = 0;
            this.tabPageTemplate.Text = "Template";
            this.tabPageTemplate.UseVisualStyleBackColor = true;
            // 
            // textBoxTemplate
            // 
            this.textBoxTemplate.AcceptsReturn = true;
            this.textBoxTemplate.AcceptsTab = true;
            this.textBoxTemplate.Dock = System.Windows.Forms.DockStyle.Fill;
            this.textBoxTemplate.Location = new System.Drawing.Point(3, 3);
            this.textBoxTemplate.Multiline = true;
            this.textBoxTemplate.Name = "textBoxTemplate";
            this.textBoxTemplate.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.textBoxTemplate.Size = new System.Drawing.Size(534, 185);
            this.textBoxTemplate.TabIndex = 0;
            // 
            // tabPageGeneratedCode
            // 
            this.tabPageGeneratedCode.Controls.Add(this.textBoxGeneratedCode);
            this.tabPageGeneratedCode.Location = new System.Drawing.Point(4, 22);
            this.tabPageGeneratedCode.Name = "tabPageGeneratedCode";
            this.tabPageGeneratedCode.Padding = new System.Windows.Forms.Padding(3);
            this.tabPageGeneratedCode.Size = new System.Drawing.Size(540, 191);
            this.tabPageGeneratedCode.TabIndex = 1;
            this.tabPageGeneratedCode.Text = "GeneratedCode";
            this.tabPageGeneratedCode.UseVisualStyleBackColor = true;
            // 
            // textBoxGeneratedCode
            // 
            this.textBoxGeneratedCode.Dock = System.Windows.Forms.DockStyle.Fill;
            this.textBoxGeneratedCode.Location = new System.Drawing.Point(3, 3);
            this.textBoxGeneratedCode.Multiline = true;
            this.textBoxGeneratedCode.Name = "textBoxGeneratedCode";
            this.textBoxGeneratedCode.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.textBoxGeneratedCode.Size = new System.Drawing.Size(534, 185);
            this.textBoxGeneratedCode.TabIndex = 1;
            // 
            // tabPageOutput
            // 
            this.tabPageOutput.Controls.Add(this.textBoxOutput);
            this.tabPageOutput.Location = new System.Drawing.Point(4, 22);
            this.tabPageOutput.Name = "tabPageOutput";
            this.tabPageOutput.Padding = new System.Windows.Forms.Padding(3);
            this.tabPageOutput.Size = new System.Drawing.Size(540, 191);
            this.tabPageOutput.TabIndex = 2;
            this.tabPageOutput.Text = "Output";
            this.tabPageOutput.UseVisualStyleBackColor = true;
            // 
            // textBoxOutput
            // 
            this.textBoxOutput.Dock = System.Windows.Forms.DockStyle.Fill;
            this.textBoxOutput.Location = new System.Drawing.Point(3, 3);
            this.textBoxOutput.Multiline = true;
            this.textBoxOutput.Name = "textBoxOutput";
            this.textBoxOutput.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.textBoxOutput.Size = new System.Drawing.Size(534, 185);
            this.textBoxOutput.TabIndex = 1;
            // 
            // tabPageUsingLibraries
            // 
            this.tabPageUsingLibraries.Controls.Add(this.textBoxUsingLibraries);
            this.tabPageUsingLibraries.Location = new System.Drawing.Point(4, 22);
            this.tabPageUsingLibraries.Name = "tabPageUsingLibraries";
            this.tabPageUsingLibraries.Padding = new System.Windows.Forms.Padding(3);
            this.tabPageUsingLibraries.Size = new System.Drawing.Size(540, 191);
            this.tabPageUsingLibraries.TabIndex = 3;
            this.tabPageUsingLibraries.Text = "Using_Libraries";
            this.tabPageUsingLibraries.UseVisualStyleBackColor = true;
            // 
            // textBoxUsingLibraries
            // 
            this.textBoxUsingLibraries.AcceptsReturn = true;
            this.textBoxUsingLibraries.AcceptsTab = true;
            this.textBoxUsingLibraries.Dock = System.Windows.Forms.DockStyle.Fill;
            this.textBoxUsingLibraries.Location = new System.Drawing.Point(3, 3);
            this.textBoxUsingLibraries.Multiline = true;
            this.textBoxUsingLibraries.Name = "textBoxUsingLibraries";
            this.textBoxUsingLibraries.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.textBoxUsingLibraries.Size = new System.Drawing.Size(534, 185);
            this.textBoxUsingLibraries.TabIndex = 1;
            // 
            // tabPageReferences
            // 
            this.tabPageReferences.Controls.Add(this.textBoxReferences);
            this.tabPageReferences.Location = new System.Drawing.Point(4, 22);
            this.tabPageReferences.Name = "tabPageReferences";
            this.tabPageReferences.Padding = new System.Windows.Forms.Padding(3);
            this.tabPageReferences.Size = new System.Drawing.Size(540, 191);
            this.tabPageReferences.TabIndex = 4;
            this.tabPageReferences.Text = "References";
            this.tabPageReferences.UseVisualStyleBackColor = true;
            // 
            // textBoxReferences
            // 
            this.textBoxReferences.AcceptsReturn = true;
            this.textBoxReferences.AcceptsTab = true;
            this.textBoxReferences.Dock = System.Windows.Forms.DockStyle.Fill;
            this.textBoxReferences.Location = new System.Drawing.Point(3, 3);
            this.textBoxReferences.Multiline = true;
            this.textBoxReferences.Name = "textBoxReferences";
            this.textBoxReferences.ScrollBars = System.Windows.Forms.ScrollBars.Both;
            this.textBoxReferences.Size = new System.Drawing.Size(534, 185);
            this.textBoxReferences.TabIndex = 1;
            // 
            // menuStrip1
            // 
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fileToolStripMenuItem,
            this.aboutToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(548, 24);
            this.menuStrip1.TabIndex = 2;
            this.menuStrip1.Text = "menuStrip1";
            // 
            // fileToolStripMenuItem
            // 
            this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.newToolStripMenuItem,
            this.openToolStripMenuItem,
            this.saveToolStripMenuItem,
            this.exitToolStripMenuItem,
            this.exitToolStripMenuItem1});
            this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
            this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20);
            this.fileToolStripMenuItem.Text = "&File";
            // 
            // newToolStripMenuItem
            // 
            this.newToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("newToolStripMenuItem.Image")));
            this.newToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.newToolStripMenuItem.Name = "newToolStripMenuItem";
            this.newToolStripMenuItem.Size = new System.Drawing.Size(100, 22);
            this.newToolStripMenuItem.Text = "&New";
            this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click);
            // 
            // openToolStripMenuItem
            // 
            this.openToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("openToolStripMenuItem.Image")));
            this.openToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.openToolStripMenuItem.Name = "openToolStripMenuItem";
            this.openToolStripMenuItem.Size = new System.Drawing.Size(100, 22);
            this.openToolStripMenuItem.Text = "&Open";
            this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
            // 
            // saveToolStripMenuItem
            // 
            this.saveToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("saveToolStripMenuItem.Image")));
            this.saveToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
            this.saveToolStripMenuItem.Size = new System.Drawing.Size(100, 22);
            this.saveToolStripMenuItem.Text = "&Save";
            this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
            // 
            // exitToolStripMenuItem
            // 
            this.exitToolStripMenuItem.Image = ((System.Drawing.Image)(resources.GetObject("exitToolStripMenuItem.Image")));
            this.exitToolStripMenuItem.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
            this.exitToolStripMenuItem.Size = new System.Drawing.Size(100, 22);
            this.exitToolStripMenuItem.Text = "&Run";
            this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
            // 
            // exitToolStripMenuItem1
            // 
            this.exitToolStripMenuItem1.Name = "exitToolStripMenuItem1";
            this.exitToolStripMenuItem1.Size = new System.Drawing.Size(100, 22);
            this.exitToolStripMenuItem1.Text = "E&xit";
            // 
            // aboutToolStripMenuItem
            // 
            this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
            this.aboutToolStripMenuItem.Size = new System.Drawing.Size(48, 20);
            this.aboutToolStripMenuItem.Text = "&About";
            this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
            // 
            // openFileDialog1
            // 
            this.openFileDialog1.FileName = "openFileDialog1";
            // 
            // MainForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(548, 266);
            this.Controls.Add(this.tabTemplateEngine);
            this.Controls.Add(this.toolStrip1);
            this.Controls.Add(this.menuStrip1);
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "MainForm";
            this.Text = "Smart Template Engine";
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.tabTemplateEngine.ResumeLayout(false);
            this.tabPageTemplate.ResumeLayout(false);
            this.tabPageTemplate.PerformLayout();
            this.tabPageGeneratedCode.ResumeLayout(false);
            this.tabPageGeneratedCode.PerformLayout();
            this.tabPageOutput.ResumeLayout(false);
            this.tabPageOutput.PerformLayout();
            this.tabPageUsingLibraries.ResumeLayout(false);
            this.tabPageUsingLibraries.PerformLayout();
            this.tabPageReferences.ResumeLayout(false);
            this.tabPageReferences.PerformLayout();
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.ToolStrip toolStrip1;
        private System.Windows.Forms.TabControl tabTemplateEngine;
        private System.Windows.Forms.TabPage tabPageTemplate;
        private System.Windows.Forms.TabPage tabPageGeneratedCode;
        private System.Windows.Forms.TabPage tabPageOutput;
        private System.Windows.Forms.ToolStripButton toolStripButtonRun;
        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem1;
        private System.Windows.Forms.TextBox textBoxTemplate;
        private System.Windows.Forms.TextBox textBoxGeneratedCode;
        private System.Windows.Forms.TextBox textBoxOutput;
        private System.Windows.Forms.ToolStripButton toolStripButtonOpen;
        private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
        private System.Windows.Forms.OpenFileDialog openFileDialog1;
        private System.Windows.Forms.SaveFileDialog saveFileDialog1;
        private System.Windows.Forms.ToolStripButton toolStripButtonSave;
        private System.Windows.Forms.ToolStripButton toolStripButtonNew;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
        private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItem;
        private System.Windows.Forms.ToolStripSeparator toolStripSeparator2;
        private System.Windows.Forms.ToolStripLabel toolStripLabelStatus;
        private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem;
        private System.Windows.Forms.TabPage tabPageUsingLibraries;
        private System.Windows.Forms.TabPage tabPageReferences;
        private System.Windows.Forms.TextBox textBoxUsingLibraries;
        private System.Windows.Forms.TextBox textBoxReferences;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Australia Australia
I have been awarded MVP (Visual C#) for year 2007, 2008, 2009. I am a Microsoft Certified Application Developer (C# .Net). I currently live in Melbourne, Australia. I am a co-founder and core developer of Pageflakes www.pageflakes.com and Founder of Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. Simplexhub.
My BLOG http://www.geekswithblogs.net/shahed
http://msmvps.com/blogs/shahed/Default.aspx.

Comments and Discussions