public ICodeDocument[] AddDocuments(CompilerDocumentInfo[] documents) { Debug.Assert(!(workspace is null)); var newDocuments = new List <RoslynCodeDocument>(); foreach (var doc in documents) { newDocuments.Add(CreateDocument(projectId, doc)); } this.documents.AddRange(newDocuments); foreach (var doc in newDocuments) { workspace.AddDocument(doc.Info); } foreach (var doc in newDocuments) { workspace.OpenDocument(doc.Info.Id); } foreach (var doc in newDocuments) { if (textViewUndoManagerProvider.TryGetTextViewUndoManager(doc.TextView, out var manager)) { manager.ClearUndoHistory(); } } return(newDocuments.ToArray()); }
public ICodeDocument[] AddDecompiledCode(IDecompiledCodeResult decompiledCodeResult) { Debug.Assert(workspace == null); workspace = new AdhocWorkspace(RoslynMefHostServices.DefaultServices); workspace.WorkspaceChanged += Workspace_WorkspaceChanged; var refs = decompiledCodeResult.AssemblyReferences.Select(a => a.CreateMetadataReference(docFactory)).ToArray(); var projectId = ProjectId.CreateNewId(); foreach (var doc in decompiledCodeResult.Documents) { documents.Add(CreateDocument(projectId, doc)); } var compilationOptions = CompilationOptions .WithOptimizationLevel(OptimizationLevel.Release) .WithPlatform(GetPlatform(decompiledCodeResult.Platform)) .WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default); if (decompiledCodeResult.PublicKey != null) { compilationOptions = compilationOptions .WithCryptoPublicKey(ImmutableArray.Create <byte>(decompiledCodeResult.PublicKey)) .WithDelaySign(true); } var projectInfo = ProjectInfo.Create(projectId, VersionStamp.Create(), "compilecodeproj", decompiledCodeResult.AssemblyName, LanguageName, compilationOptions: compilationOptions, parseOptions: ParseOptions, documents: documents.Select(a => a.Info), metadataReferences: refs, isSubmission: false, hostObjectType: null); workspace.AddProject(projectInfo); foreach (var doc in documents) { workspace.OpenDocument(doc.Info.Id); } foreach (var doc in documents) { if (textViewUndoManagerProvider.TryGetTextViewUndoManager(doc.TextView, out var manager)) { manager.ClearUndoHistory(); } } return(documents.ToArray()); }