c语言编译器:.NET语言开发自己的脚本语言(二)--动态编译



动态编译:
using ;
using .IO;
using .Text;
using Microsoft.CSharp;

TestProject
{
public 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 .Collections.IDictionary configs = null;//编译属性参数配置

public DynamicCompile
{}

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

延伸阅读

最新评论

发表评论