使用CODEDOM动态实现代码的生成,编译
前一阶段一直在做一个基于VS.NET2k3的一个插件,大致功能是实现业务代码的自动生成。程序在前几天终于突破性的进展,所有的功能都能实现了。包括自动添加工程,引用,编译等。等再过些天,把代码进行优化一些(同时去除一些BUG,一直不明白,当产生几万行代码后,我的开发环境会全面崩溃了)再发布出来吧。昨天突然想到,现在产生的代码过于生,不能根据用户的选择来生成对应的语言的代码。如果死写的话,也太没意思了。想到以前曾看过MSDN里介绍过CODEDOM这玩意能生成各门语言的代码,能动态调用编译,于是快速将CODEDOM再看一次,果然能生成C#,VB,JSCRIPT的代码。不过刚开始研究,只写了一个小小的程序。不过也觉得很有意思的。这样的话,我只要将我的TOOLKIT重写一下就可以让不同的程序员根据自己的喜好生成对应的代码了(功能都是一样的。)
using System;
using System.CodeDom;
using System.CodeDom.Compiler;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Microsoft.CSharp;
using Microsoft.VisualBasic;
using Microsoft.JScript;
//这个示例演示如何使用System.CodeDom来建立一个HELLO World程序,将会根据用户的选择动态代码生成及编译的C#,VB,JScript版本的程序集
namespace CodeDOMTest
{
public class CodeDomExampleForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button run_button = new System.Windows.Forms.Button();
private System.Windows.Forms.Button compile_button = new System.Windows.Forms.Button();
private System.Windows.Forms.Button generate_button = new System.Windows.Forms.Button();
private System.Windows.Forms.TextBox textBox1 = new System.Windows.Forms.TextBox();
private System.Windows.Forms.ComboBox comboBox1 = new System.Windows.Forms.ComboBox();
private System.Windows.Forms.Label label1 = new System.Windows.Forms.Label();
