public static Ast_CSharp mapCodeO2References(this Ast_CSharp astCSharp, CSharp_FastCompiler_CompilerOptions compilerOptions) { compilerOptions.ExtraSourceCodeFilesToCompile = new List <string>(); var compilationUnit = astCSharp.CompilationUnit; compilerOptions.ReferencedAssemblies = new List <string>(); // this should be cleared in a more global location compilerOptions.Extra_Using_Statements = new List <string>(); // same here var filesToDownload = new List <string>(); var currentUsingDeclarations = new List <string>(); foreach (var usingDeclaration in astCSharp.AstDetails.UsingDeclarations) { currentUsingDeclarations.Add(usingDeclaration.Text); } compilerOptions.mapOptionsDefinedInsideComments(astCSharp.AstDetails.comments()) .mapNuGetReferences() .Extra_Using_Statements.forEach(value => astCSharp.CompilationUnit.add_Using(value)); //resolve location of ExtraSourceCodeFilesToCompile astCSharp.resolveFileLocationsOfExtraSourceCodeFilesToCompile(compilerOptions); CompileEngine.handleReferencedAssembliesInstallRequirements(astCSharp.AstDetails.CSharpCode); //use the same technique to download files that are needed for this script (for example *.zip files or other unmanaged/support files) CompileEngine.tryToResolveReferencesForCompilation(filesToDownload, compilerOptions.WorkOffline); if (compilerOptions.onlyAddReferencedAssemblies.isFalse()) { foreach (var defaultRefAssembly in CompileEngine.DefaultReferencedAssemblies) { if (compilerOptions.ReferencedAssemblies.Contains(defaultRefAssembly).isFalse()) { compilerOptions.ReferencedAssemblies.add(defaultRefAssembly); } } foreach (var usingStatement in CompileEngine.DefaultUsingStatements) { if (false == currentUsingDeclarations.Contains(usingStatement)) { compilationUnit.add_Using(usingStatement); } } } //make sure the referenced assemblies are in the current execution directory CompileEngine.tryToResolveReferencesForCompilation(compilerOptions.ReferencedAssemblies, compilerOptions.WorkOffline); return(astCSharp); }
public void mapCodeO2References(Ast_CSharp astCSharp) { bool onlyAddReferencedAssemblies = false; ExtraSourceCodeFilesToCompile = new List <string>(); var compilationUnit = astCSharp.CompilationUnit; ReferencedAssemblies = new List <string>(); var filesToDownload = new List <string>(); var currentUsingDeclarations = new List <string>(); foreach (var usingDeclaration in astCSharp.AstDetails.UsingDeclarations) { currentUsingDeclarations.Add(usingDeclaration.Text); } foreach (var comment in astCSharp.AstDetails.Comments) { comment.Text.eq("O2Tag_OnlyAddReferencedAssemblies", () => onlyAddReferencedAssemblies = true); comment.Text.starts("using ", false, value => astCSharp.CompilationUnit.add_Using(value)); comment.Text.starts(new [] { "ref ", "O2Ref:" }, false, value => ReferencedAssemblies.Add(value)); comment.Text.starts(new[] { "Download:", "download:", "O2Download:" }, false, value => filesToDownload.Add(value)); comment.Text.starts(new[] { "include", "file ", "O2File:" }, false, value => ExtraSourceCodeFilesToCompile.Add(value)); comment.Text.starts(new[] { "dir ", "O2Dir:" }, false, value => ExtraSourceCodeFilesToCompile.AddRange(value.files("*.cs", true))); comment.Text.starts(new[] { "O2:debugSymbols", "generateDebugSymbols", "debugSymbols" }, true, (value) => generateDebugSymbols = true); comment.Text.starts(new[] { "SetInvocationParametersToDynamic" }, (value) => ResolveInvocationParametersType = false); comment.Text.starts(new[] { "DontSetInvocationParametersToDynamic" }, (value) => ResolveInvocationParametersType = true); comment.Text.eq("StaThread", () => { ExecuteInStaThread = true; }); comment.Text.eq("MtaThread", () => { ExecuteInMtaThread = true; }); comment.Text.eq("WorkOffline", () => { WorkOffline = true; }); } //resolve location of ExtraSourceCodeFilesToCompile resolveFileLocationsOfExtraSourceCodeFilesToCompile(); CompileEngine.handleReferencedAssembliesInstallRequirements(astCSharp.AstDetails.CSharpCode); //use the same technique to download files that are needed for this script (for example *.zip files or other unmanaged/support files) CompileEngine.tryToResolveReferencesForCompilation(filesToDownload, WorkOffline); if (onlyAddReferencedAssemblies.isFalse()) { foreach (var defaultRefAssembly in CompileEngine.DefaultReferencedAssemblies) { if (ReferencedAssemblies.Contains(defaultRefAssembly).isFalse()) { ReferencedAssemblies.add(defaultRefAssembly); } } foreach (var usingStatement in CompileEngine.DefaultUsingStatements) { if (false == currentUsingDeclarations.Contains(usingStatement)) { compilationUnit.add_Using(usingStatement); } } } //make sure the referenced assemblies are in the current execution directory CompileEngine.tryToResolveReferencesForCompilation(ReferencedAssemblies, WorkOffline); }