public CompilerResults Compile(DirectoryInfo[] directories, string assemblyFileName, string[] referenceAssemblies = null, bool executable = false) { if (referenceAssemblies == null) { referenceAssemblies = DefaultReferenceAssemblies.ToArray(); } return(AdHocCSharpCompiler.CompileDirectories(directories, assemblyFileName, referenceAssemblies, executable)); }
public CompilerResults Compile(string[] sources, string assemblyFileName, string[] referenceAssemblies = null, bool executable = false) { if (referenceAssemblies == null) { referenceAssemblies = new string[0]; } CSharpCodeProvider codeProvider = new CSharpCodeProvider(); CompilerParameters parameters = AdHocCSharpCompiler.GetCompilerParameters(assemblyFileName, referenceAssemblies, executable); return(codeProvider.CompileAssemblyFromSource(parameters, sources)); }
public GeneratedAssemblyInfo Compile(string sourcePath, string fileName = null) { fileName = fileName ?? FileName; CompilerResults compileResult = AdHocCSharpCompiler.CompileDirectory(new DirectoryInfo(sourcePath), fileName, ReferenceAssemblyPaths, false); if (compileResult.Errors.Count > 0) { throw new CompilationException(compileResult); } GeneratedAssemblyInfo result = new GeneratedAssemblyInfo(FilePath, compileResult); result.Save(); return(result); }
public GeneratedAssemblyInfo GenerateAssembly() { Args.ThrowIfNullOrEmpty(AssemblyName, nameof(AssemblyName)); GeneratedAssemblyInfo result = null; AutoResetEvent wait = new AutoResetEvent(false); GenerateCsFiles(Types, (o, a) => { CompilerResults compilerResults = AdHocCSharpCompiler.CompileDirectory(new DirectoryInfo(CsFileDirectory), AssemblyName, new Assembly[] { typeof(IMessage).Assembly }); result = new GeneratedAssemblyInfo(AssemblyName, compilerResults); wait.Set(); }); wait.WaitOne(); return(result); }
public void FuncCompilerTest() { string code = @" using System; public class FuncProvider { public Func<bool> GetFunc() { return (Func<bool>)(() => $Code$); } }"; CompilerResults results = AdHocCSharpCompiler.CompileSource(code.Replace("$Code$", "true"), "TestAssembly"); Func <bool> o = (Func <bool>)results.CompiledAssembly.GetType("FuncProvider").Construct().Invoke("GetFunc"); Expect.IsTrue(o()); }
public void ShouldBeAbleToDownloadAndCompileCSharpProxy() { BamServer server; SecureServiceProxyClient <EncryptedEcho> sspc; ServiceProxyTestHelpers.StartSecureChannelTestServerGetEncryptedEchoClient(out server, out sspc); string value = Http.Get("http://localhost:8080/ServiceProxy/CSharpProxies?namespace=My.Test.Namespace&classes=EncryptedEcho"); FileInfo codeFile = new FileInfo(".\\Tmp\\code.cs"); if (codeFile.Directory.Exists) { codeFile.Directory.Delete(true); } codeFile.Directory.Create(); value.SafeWriteToFile(codeFile.FullName, true); List <string> referenceAssemblies = new List <string>(DaoGenerator.DefaultReferenceAssemblies); referenceAssemblies.Add(typeof(ServiceProxyClient).Assembly.GetFileInfo().FullName); referenceAssemblies.Add(typeof(BamServer).Assembly.GetFileInfo().FullName); CompilerResults results = AdHocCSharpCompiler.CompileDirectories(new DirectoryInfo[] { codeFile.Directory }, ".\\Tmp\\TestClients.dll", referenceAssemblies.ToArray(), false); if (results.Errors.Count > 0) { StringBuilder message = new StringBuilder(); foreach (CompilerError err in results.Errors) { message.AppendLine(string.Format("File=>{0}\r\n{1}:::Line {2}, Column {3}::{4}", err.FileName, err.ErrorNumber, err.Line, err.Column, err.ErrorText)); } OutLine(message.ToString(), ConsoleColor.Red); } Expect.AreEqual(0, results.Errors.Count); Expect.IsTrue(results.CompiledAssembly.GetFileInfo().Exists); server.Stop(); }
public GeneratedAssemblyInfo GenerateAssembly() { OnAssemblyGenerating(new ProxyAssemblyGenerationEventArgs { ServiceType = ServiceType, ServiceSettings = ServiceSettings }); ProxyModel proxyModel = RenderCode(); CompilerResults compileResult = AdHocCSharpCompiler.CompileSource(Code.ToString(), FileName, proxyModel.ReferenceAssemblies); if (compileResult.Errors.Count > 0) { throw new CompilationException(compileResult); } GeneratedAssemblyInfo result = new GeneratedAssemblyInfo(FileName, compileResult); result.Save(); OnAssemblyGenerated(new ProxyAssemblyGenerationEventArgs { ServiceType = ServiceType, ServiceSettings = ServiceSettings }); return(result); }
public Assembly GetAssembly(string nameSpace = null) { List <DynamicTypeDescriptor> types = new List <DynamicTypeDescriptor>(); DynamicNamespaceDescriptor ns = null; if (nameSpace != null) { ns = GetNamespaceDescriptor(nameSpace); } else { ns = DynamicTypeDataRepository.GetOneDynamicNamespaceDescriptorWhere(d => d.Namespace == DynamicNamespaceDescriptor.DefaultNamespace); } types = DynamicTypeDataRepository.DynamicTypeDescriptorsWhere(t => t.DynamicNamespaceDescriptorId == ns.Id).ToList(); StringBuilder src = new StringBuilder(); foreach (DynamicTypeDescriptor typeDescriptor in types) { DtoModel dto = new DtoModel ( ns.Namespace, GetClrTypeName(typeDescriptor.TypeName), typeDescriptor.Properties.Select(p => new DtoPropertyModel { PropertyName = GetClrPropertyName(p.PropertyName), PropertyType = GetClrTypeName(p.PropertyType) }).ToArray() ); src.AppendLine(dto.Render()); } CompilerResults results = AdHocCSharpCompiler.CompileSource(src.ToString(), $"{ns.Namespace}.dll"); if (results.Errors.Count > 0) { throw new CompilationException(results); } return(results.CompiledAssembly); }
private static void Compile(DirectoryInfo[] dirs, FileInfo file) { DaoGenerator generator = new DaoGenerator(GetNamespace()); CompilerResults results = AdHocCSharpCompiler.CompileDirectories(dirs, file.Name, DaoGenerator.DefaultReferenceAssemblies.ToArray(), false); OutputCompilerErrors(results); }