本文整理汇总了C#中Microsoft.CodeAnalysis.AdhocWorkspace.OpenDocument方法的典型用法代码示例。如果您正苦于以下问题:C# AdhocWorkspace.OpenDocument方法的具体用法?C# AdhocWorkspace.OpenDocument怎么用?C# AdhocWorkspace.OpenDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.AdhocWorkspace
的用法示例。
在下文中一共展示了AdhocWorkspace.OpenDocument方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddDecompiledCode
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 projectInfo = ProjectInfo.Create(projectId, VersionStamp.Create(), "compilecodeproj", Guid.NewGuid().ToString(), LanguageName,
compilationOptions: CompilationOptions
.WithOptimizationLevel(OptimizationLevel.Release)
.WithPlatform(GetPlatform(decompiledCodeResult.Platform))
.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default),
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) {
ITextViewUndoManager manager;
if (textViewUndoManagerProvider.TryGetTextViewUndoManager(doc.TextView, out manager))
manager.ClearUndoHistory();
}
return documents.ToArray();
}
示例2: InitializeAsync
async Task InitializeAsync(ITextBuffer buffer, string code, MetadataReference[] refs, string languageName, ISynchronousTagger<IClassificationTag> tagger, CompilationOptions compilationOptions, ParseOptions parseOptions) {
using (var workspace = new AdhocWorkspace(RoslynMefHostServices.DefaultServices)) {
var documents = new List<DocumentInfo>();
var projectId = ProjectId.CreateNewId();
documents.Add(DocumentInfo.Create(DocumentId.CreateNewId(projectId), "main.cs", null, SourceCodeKind.Regular, TextLoader.From(buffer.AsTextContainer(), VersionStamp.Create())));
var projectInfo = ProjectInfo.Create(projectId, VersionStamp.Create(), "compilecodeproj", Guid.NewGuid().ToString(), languageName,
compilationOptions: compilationOptions
.WithOptimizationLevel(OptimizationLevel.Release)
.WithPlatform(Platform.AnyCpu)
.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default),
parseOptions: parseOptions,
documents: documents,
metadataReferences: refs,
isSubmission: false, hostObjectType: null);
workspace.AddProject(projectInfo);
foreach (var doc in documents)
workspace.OpenDocument(doc.Id);
buffer.Replace(new Span(0, buffer.CurrentSnapshot.Length), code);
{
// Initialize classification code paths
var spans = new NormalizedSnapshotSpanCollection(new SnapshotSpan(buffer.CurrentSnapshot, 0, buffer.CurrentSnapshot.Length));
foreach (var tagSpan in tagger.GetTags(spans, CancellationToken.None)) { }
}
{
// Initialize completion code paths
var info = CompletionInfo.Create(buffer.CurrentSnapshot);
Debug.Assert(info != null);
if (info != null) {
var completionTrigger = CompletionTrigger.Default;
var completionList = await info.Value.CompletionService.GetCompletionsAsync(info.Value.Document, 0, completionTrigger);
}
}
{
// Initialize signature help code paths
var info = SignatureHelpInfo.Create(buffer.CurrentSnapshot);
Debug.Assert(info != null);
if (info != null) {
int sigHelpIndex = code.IndexOf("sighelp");
Debug.Assert(sigHelpIndex >= 0);
var triggerInfo = new SignatureHelpTriggerInfo(SignatureHelpTriggerReason.InvokeSignatureHelpCommand);
var items = await info.Value.SignatureHelpService.GetItemsAsync(info.Value.Document, sigHelpIndex, triggerInfo);
}
}
{
// Initialize quick info code paths
var info = QuickInfoState.Create(buffer.CurrentSnapshot);
Debug.Assert(info != null);
if (info != null) {
int quickInfoIndex = code.IndexOf("Equals");
Debug.Assert(quickInfoIndex >= 0);
var item = await info.Value.QuickInfoService.GetItemAsync(info.Value.Document, quickInfoIndex);
}
}
}
}