六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

使用CodeDom來(lái)生成.cs文件

[摘要]在學(xué)使用CodeDom來(lái)動(dòng)態(tài)生成.cs文件,使用幫助里的例子,代碼居然編譯不通過自己修改,調(diào)試通過,整理后主要代碼如下:命名空間:using System.CodeDom;using System.CodeDom.Compiler;using Microsoft.CSharp;using Syst...
在學(xué)使用CodeDom來(lái)動(dòng)態(tài)生成.cs文件,使用幫助里的例子,代碼居然編譯不通過
自己修改,調(diào)試通過,整理后主要代碼如下:

命名空間:
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
using System.IO;

??private void button1_Click(object sender, System.EventArgs e)
??{
???CodeCompileUnit CompileUnit = new CodeCompileUnit();
???CodeNamespace Samples = new CodeNamespace("Samples");
???Samples.Imports.Add( new CodeNamespaceImport("System") );
???CompileUnit.Namespaces.Add( Samples );
???CodeTypeDeclaration Class1 = new CodeTypeDeclaration("Class1");
???Samples.Types.Add(Class1);

???CodeEntryPointMethod Start = new CodeEntryPointMethod();
???
???//輸出HelloWord
???CodeMethodInvokeExpression cs1 = new CodeMethodInvokeExpression( new
????CodeTypeReferenceExpression("System.Console"), "WriteLine", new
????CodePrimitiveExpression("Hello World!") );
???
???Start.Statements.Add(cs1);
???

???Class1.Members.Add( Start );
???//CSharpCodeProvider provider = new CSharpCodeProvider();
???//ICodeGenerator gen = provider.CreateGenerator();
???GenerateGraph(CompileUnit);

??}
??public void GenerateGraph(CodeCompileUnit compileunit)
??{
???// Obtains an ICodeGenerator from a CodeDomProvider class.
???CSharpCodeProvider provider = new CSharpCodeProvider();
???ICodeGenerator gen = provider.CreateGenerator();
??
???// Creates a StreamWriter to an output file.
???StreamWriter sw = new StreamWriter("d:\\TestGraph.cs", false);

???// Generates source code using the code generator.
???gen.GenerateCodeFromCompileUnit(compileunit, sw, new??? CodeGeneratorOptions());
??
???// Closes the output files.
???sw.Close();
??}

??private void button2_Click(object sender, System.EventArgs e)
??{
???CompileCode("d:\\TestGraph.cs");
??}
??//編輯生成Exe
??public CompilerResults CompileCode(string filepath)
??{
???// Obtains an ICodeCompiler from a CodeDomProvider class.
???CSharpCodeProvider provider = new CSharpCodeProvider();
???ICodeCompiler compiler = provider.CreateCompiler();

???// Configures a compiler parameters object which links System.dll and
???// generates a file name based on the specified source file name.
???CompilerParameters cp = new CompilerParameters(new string[] {"System.dll"}, filepath.Substring(0, filepath.LastIndexOf(".")+1)+"exe", false);

???// Indicates that an executable rather than a .dll should be generated.
???cp.GenerateExecutable = true;

???// Invokes compilation.
???CompilerResults cr = compiler.CompileAssemblyFromFile(cp, filepath);??

???// Returns the results of compilation.
???return cr;???????
??}

幫助里的例子在:
.NET Framework->使用 .NET Framework 編程->動(dòng)態(tài)生成和編譯以多種語(yǔ)言表示的源代碼


主站蜘蛛池模板: 亚洲日日夜夜 | 日本草草影院 | 欧美综合在线播放 | 天天干天天操天天操 | 色中文在线 | 宇都宫紫苑日韩专区亚洲 | 亚洲sss| 天天操天天干天天爽 | 在线视频第一页 | 亚色网站| 天天操天天爽天天射 | 亚洲色大成网站www 亚洲三级中文字幕 | 四虎精品国产一区二区三区 | 欧美影院一区二区三区 | 青青草视频免费观看 | 在线观看男女爱视频网站 | 午夜性爽视频男人的天堂在线 | 欧美一区二区激情三区 | 五月花精品视频在线观看 | 欧美一级性生活视频 | 亚洲福利 | 四虎影院成人 | 天天操天天操 | 亚洲欧美日韩在线2020 | 日韩中文在线观看 | 午夜精品久久久久久久99热下载 | 天天看天天干 | 日日干日日 | 日本韩国欧美三级 | 日韩不卡在线 | 青青青草视频在线 | 青青在线视频免费观看 | 视频一区二区三区蜜桃麻豆 | 亚洲免费高清视频 | 色呦呦免费观看 | 一级免费黄色 | 青青精品 | 最近新免费韩国视频资源 | 在线欧美a | 中文字幕免费高清视频 | 五月天色区 |