public static object ExecuteCsCode(string code, object parameters) { if (string.IsNullOrEmpty(code)) { throw new ArgumentNullException("code"); } if (parameters == null) { throw new ArgumentNullException("parameters"); } // 因为脚本可以重复执行,脚本会被重新编译,为了能正常卸载临时程序集,这里采用应用程序域来解决。 AppDomain domain = AppDomain.CreateDomain("PreheatWebSite_ExecuteDomain"); try { CompilerProxy server = (CompilerProxy)domain.CreateInstanceAndUnwrap( typeof(CompilerProxy).Assembly.FullName, typeof(CompilerProxy).FullName); // 执行脚本 return((Dictionary <string, string>)server.Execute(code, parameters)); } finally { AppDomain.Unload(domain); } }
private void ExecuteCsCode() { if (string.IsNullOrEmpty(_currentExecuteInfo.CsCode)) { return; } object result = CompilerProxy.ExecuteCsCode(_currentExecuteInfo.CsCode, _currentExecuteInfo.Parameters); _currentExecuteInfo.Parameters = (Dictionary <string, string>)result; }