public String Compile(String code) { CSharpCodeProvider provider = new CSharpCodeProvider(); CompilerParameters cp = new CompilerParameters { GenerateInMemory = true }; cp.ReferencedAssemblies.Add("System.dll"); cp.ReferencedAssemblies.Add("System.Data.dll"); cp.ReferencedAssemblies.Add(Path.Combine(BinPath, "Codaxy.Dextop.dll")); var rc = RewriteCode(code); var results = provider.CompileAssemblyFromSource(cp, rc); foreach (CompilerError error in results.Errors) { throw new Exception(error.ErrorText); } var assembly = results.CompiledAssembly; StringBuilder res = new StringBuilder(); var app = new PreviewerApplication(); using (var ss = new MemoryStream()) { IDextopAssemblyPreprocessor columnProcessor = new Data.DextopGridHeaderPreprocessor(); columnProcessor.ProcessAssemblies(app, new[] { assembly }, ss, null); res.AppendLine(Encoding.UTF8.GetString(ss.ToArray())); } using (var ss = new MemoryStream()) { IDextopAssemblyPreprocessor formProcessor = new Forms.DextopFormPreprocessor(); formProcessor.ProcessAssemblies(app, new[] { assembly }, ss, null); res.AppendLine(Encoding.UTF8.GetString(ss.ToArray())); } return(res.ToString()); }
public String Compile(String code) { CSharpCodeProvider provider = new CSharpCodeProvider(); CompilerParameters cp = new CompilerParameters { GenerateInMemory = true }; cp.ReferencedAssemblies.Add("System.dll"); cp.ReferencedAssemblies.Add("System.Data.dll"); cp.ReferencedAssemblies.Add(Path.Combine(BinPath, "Codaxy.Dextop.dll")); var rc = RewriteCode(code); var results = provider.CompileAssemblyFromSource(cp, rc); foreach (CompilerError error in results.Errors) throw new Exception(error.ErrorText); var assembly = results.CompiledAssembly; StringBuilder res = new StringBuilder(); var app = new PreviewerApplication(); using (var ss = new MemoryStream()) { IDextopAssemblyPreprocessor columnProcessor = new Data.DextopGridHeaderPreprocessor(); columnProcessor.ProcessAssemblies(app, new[] { assembly }, ss, null); res.AppendLine(Encoding.UTF8.GetString(ss.ToArray())); } using (var ss = new MemoryStream()) { IDextopAssemblyPreprocessor formProcessor = new Forms.DextopFormPreprocessor(); formProcessor.ProcessAssemblies(app, new[] { assembly }, ss, null); res.AppendLine(Encoding.UTF8.GetString(ss.ToArray())); } return res.ToString(); }