保留.cs文件 生成控制台应用程序、窗口程序都是把cs文件编译好了,更改cs文件的值后需要重新编译才能更改。请问前辈,有没有办法使它能像aspx那样调用没编译的cs文件,谢谢!!(前段时间太豪爽,现在没分了) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你可以生成 但是还想在程序运行中使用 哥哥 现在的cpu不支持在运行中修改程序地 用CODEDOM好了,一会给你写个小例子...using System;using System.Reflection;using Microsoft.CSharp;using System.CodeDom.Compiler;...C#4.0中就更简单了... CODEDOM就是动态编译代码吧?速度很慢的是不是,我在自己的机里试很慢 动态编译非常不慢,还是解决"很慢场景"的通用办法一般来说,真接使用反射会慢上数百倍,所以改进的办法就是在反射上嫁接动态编译.C#4.0中,接近正常速度,其实ASPX就是这么干的. string TestString = @" public class Test { public static string Test() { string Str = ""test it !!!!""; return Str; } }"; CompilerParameters compilerParams = new CompilerParameters(); compilerParams.GenerateInMemory = true; compilerParams.IncludeDebugInformation = false; compilerParams.ReferencedAssemblies.Add("mscorlib.dll"); compilerParams.ReferencedAssemblies.Add("System.dll"); ICodeCompiler compiler = new CSharpCodeProvider().CreateCompiler(); CompilerResults results = compiler.CompileAssemblyFromSource(compilerParams, TestString); Assembly asm = results.CompiledAssembly; object objMyTestClass = asm.CreateInstance("Test"); Type MyTestClassType = objMyTestClass.GetType(); Console.WriteLine(MyTestClassType.GetMethod("Test").Invoke(objMyTestClass, null)); 请问谁熟悉MVC3.0中的脚手架功能? 关于 指定时间段查询数据库中信息问题 WinFrom 判断窗体是否已存在? 用C#绘图都用到哪些命名空间或类,最常用的是哪些类。 疑难问题~~ 请高手指教 C# Winform picturebox拖拽问题 愚翁, 小山等对SharpZipLib熟悉的朋友请进来。解决问题者再开贴送100分 数据库的操作 c# 中dll的应用? winform程序打包 安装程序后打开快捷方式有错误 vs05怎么快速插入这种注释 20090814新手求助?
一会给你写个小例子...using System;
using System.Reflection;
using Microsoft.CSharp;
using System.CodeDom.Compiler;...C#4.0中就更简单了...
还是解决"很慢场景"的通用办法一般来说,真接使用反射会慢上数百倍,
所以改进的办法就是在反射上嫁接动态编译.C#4.0中,接近正常速度,
其实ASPX就是这么干的. string TestString = @"
public class Test
{
public static string Test()
{
string Str = ""test it !!!!"";
return Str;
}
}"; CompilerParameters compilerParams = new CompilerParameters();
compilerParams.GenerateInMemory = true;
compilerParams.IncludeDebugInformation = false;
compilerParams.ReferencedAssemblies.Add("mscorlib.dll");
compilerParams.ReferencedAssemblies.Add("System.dll");
ICodeCompiler compiler = new CSharpCodeProvider().CreateCompiler();
CompilerResults results = compiler.CompileAssemblyFromSource(compilerParams, TestString);
Assembly asm = results.CompiledAssembly;
object objMyTestClass = asm.CreateInstance("Test");
Type MyTestClassType = objMyTestClass.GetType();
Console.WriteLine(MyTestClassType.GetMethod("Test").Invoke(objMyTestClass, null));