利用.NET语言开发自己的脚本语言(二)--动态编译
2005-10-16 17:40
519 查看
动态编译:
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;
}
}
}
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语言开发自己的脚本语言(一)
- 利用.NET语言开发自己的脚本语言(一)
- 利用.NET语言开发自己的脚本语言(一)
- 如何开发自己的.NET语言
- .NET 动态脚本语言
- 在线开发与编译的脚本语言
- 在.NET中动态编译与执行脚本文件
- 在线开发与编译的脚本语言
- android开发之采用perl脚本语言开发ota差异包自动编译脚本
- 让C#语言充当自身脚本!——.NET中的动态编译
- 微软放缓.NET动态语言开发计划,徐汇区网站设计
- .NET开发人员,对于动态语言(Dynamic Languages)应该持什么样的态度
- web开发 web开发(脚本和动态语言) 电子签名 active CSDN 推荐tag:win32 dll pcpos 证书 文件
- [JAVA语言学习][小技巧]利用Batch批处理脚本实现控制台快速编译执行JAVA程序
- PHP-学习笔记—— 认识脚本语言; 动态网站开发所需的Web构件儿;
- 不用Unity库,利用.NET动态代理自己实现AOP
- .NET开发人员,对于动态语言(Dynamic Languages)应该持什么样的态度
- .NET 动态脚本语言Script.NET系列文章汇总 非常精彩的应用举例
- .NET 动态脚本语言Script.NET 开发指南
- 热更新.9图下发_编译使用篇(android原生与脚本语言混合式开发)