/// <summary> /// Builds the corresponding .net core assembly from the code in the given files. /// </summary> public AssemblyInfo BuildFiles(string[] files, CompilerMetadata metadatas, QSharpLogger logger, string dllName) { var syntaxTree = BuildQsSyntaxTree(files, metadatas.QsMetadatas, logger); Uri FileUri(string f) => CompilationUnitManager.TryGetUri(NonNullable <string> .New(f), out var uri) ? uri : null; var assembly = BuildAssembly(files.Select(FileUri).ToArray(), syntaxTree, metadatas.RoslynMetadatas, logger, dllName); return(assembly); }
private FileContentManager InitializeFileManager(IEnumerable <string> examples, QsCompilation compilation, string nsName = null) { var(pre, post) = ($"namespace {nsName ?? DefaultNamespaceName}{{ {Environment.NewLine}", $"{Environment.NewLine}}}"); var openDirs = String.Join(Environment.NewLine, OpenedForTesting .Where(nsName => ContainsNamespace(compilation, nsName)) .Select(nsName => $"open {nsName};")); string WrapInNamespace(string example) => pre + openDirs + example + post; examples = examples.Where(ex => !String.IsNullOrWhiteSpace(ex)); var sourceCode = String.Join(Environment.NewLine, examples.Select(WrapInNamespace)); var sourceName = NonNullable <string> .New(Path.GetFullPath($"{nsName}{CodeSource}")); return(CompilationUnitManager.TryGetUri(sourceName, out var sourceUri) ? CompilationUnitManager.InitializeFileManager(sourceUri, sourceCode) : null); }