·首页 ·asp ·.net ·php ·JSP ·CGI ·数据库 ·网页设计 ·网管专栏 ·XML ·工具软件 ·办公软件 ·操作系统 ·程序设计 ·LINUX 
  当前位置: 普克>>计算机教程>>.net>>.NET-Framework>>利用.NET语言开发自己的脚本语言(二
flash视频教学

photoshop专题

asp.net专题

office专题

利用.NET语言开发自己的脚本语言(二)--动态编译


.NET-Framework 发表时间:2006-4-8 字体:  返回
动态编译:
using System;
using System.IO;
using System.Text;
using Microsoft.CSharp;

namespace TestProject
{
public class DynamicCompile
{
private String _physicspath = @"D:\Project.Net\TestProject\DcCodeFile\";//文件夹的路径
private String _outputpath = @"D:\Project.Net\TestProject\bin";//输出文件的路径

private String[] _filelist; //文件列表
private String[] _cscode; //源码
private String[] _filename; //文件名
private String[] _import; //引用
private System.Collections.IDictionary configs = null;//编译属性参数配置

public DynamicCompile()
{}

public CompilerError[] ExCompiler()
{
Fill_cscode();
Fill_import();
Fill_configs();
CompilerError[] ce= Compiler.Compile(_cscode,_filename, _outputpath,_import, configs);
return ce;
}
private String[] Fill_filelist()
{
return System.IO.Directory.GetFiles(_physicspath,"*.cs");
}
private void Fill_cscode()
{
_filelist= Fill_filelist();
_cscode=new String[_filelist.Length];
_filename=new String[_filelist.Length];
for(int i=0;i<_filelist.Length;i++)
{
String filepath= _filelist.GetValue(i).ToString();//获取文件路径
_cscode[i]= ReadCodeFile(filepath, Encoding.GetEncoding("utf-8"));
_filename[i]= System.IO.Path.GetFileName(filepath);
}
}
private void Fill_import()
{
_import=new String[10];//数组长度视引用文件数量
_import[0]=@"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll";
_import[1]=@"C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.dll";
}
private void Fill_configs()
{
configs=new System.Collections.Specialized.ListDictionary();
configs.Add("target","library");
}
//读取cscode内容
private String ReadCodeFile(String path,Encoding encode)
{
String content=String.Empty;
try
{
if (File.Exists(path))
{
StreamReader sr=new StreamReader(path,encode);
content=sr.ReadToEnd();
sr.Close();
}
}
catch(IOException ex)
{
Console.Write(ex.ToString());
}
return content;
}
}
}


上一篇:.Net中如何操作IIS(源代码)
下一篇:在.NET中获取一台电脑名,IP地址及当前用户名

普克创业投资网刊载此文不代表同意其说法或描述,仅为提供更多信息。
在百度中搜索利用.NET语言开发自己的脚本语言(二)--动态编译的相关内容]   [在狗狗中搜索利用.NET语言开发自己的脚本语言(二)--动态编译的相关内容]
Copyright @ 2006 PUPK.COM 普克创业投资网 版权所有
 建议使用1024*768以达到最好的浏览效果