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

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

使用CodeDom來生成.cs文件

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

命名空間:
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 編程->動態生成和編譯以多種語言表示的源代碼


主站蜘蛛池模板: 欧美一级大片在线观看 | 亚洲欧美久久婷婷爱综合一区天堂 | 日本天堂视频 | 最近的2019中文字幕免费一页 | 三级黄色在线免费观看 | 天天干在线影院 | 午夜成人免费影院 | 日本亚洲欧美在线 | 青青青在线网站视频在线 | 日韩高清欧美 | 青草久久精品亚洲综合专区 | 亚洲欧美自拍另类图片色 | 天天夜夜骑 | 日韩中文字幕精品一区在线 | 亚洲成人一级 | 亚洲第一免费网站 | 欧美香蕉在线 | 天天爱天天做色综合 | 最近韩国高清免费 hd | 五月婷婷丁香综合网 | 欧洲性开放大片免费观看视频 | 日本黄色一级大片 | 婷婷在线网 | 中文字幕高清在线天堂网 | 日韩亚洲欧美视频 | 中文字幕在线不卡 | 色婷婷影院在线视频免费播放 | 三级精品视频在线播放 | 青草久久精品亚洲综合专区 | 四虎剧院| 日本大胆欧美人术艺术 | 亚洲精品一线二线三线 | 天堂bt资源在线官网 | 欧美专区日韩 | 五月婷婷欧美 | 日韩免费毛片全部不收费 | 四虎4545www国产精品 | 在线看日本吃奶孕交 | 在线观看欧美亚洲 | 手机在线看片国产日韩生活片 | 四虎www成人影院 |