本文整理汇总了C#中Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace.OnDocumentOpened方法的典型用法代码示例。如果您正苦于以下问题:C# TestWorkspace.OnDocumentOpened方法的具体用法?C# TestWorkspace.OnDocumentOpened怎么用?C# TestWorkspace.OnDocumentOpened使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace
的用法示例。
在下文中一共展示了TestWorkspace.OnDocumentOpened方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateWorkspace
public static TestWorkspace CreateWorkspace(
XElement workspaceElement,
bool completed = true,
bool openDocuments = true,
ExportProvider exportProvider = null,
string workspaceKind = null)
{
if (workspaceElement.Name != WorkspaceElementName)
{
throw new ArgumentException();
}
exportProvider = exportProvider ?? TestExportProvider.ExportProviderWithCSharpAndVisualBasic;
var workspace = new TestWorkspace(exportProvider, workspaceKind);
var projectMap = new Dictionary<string, TestHostProject>();
var documentElementToFilePath = new Dictionary<XElement, string>();
var projectElementToAssemblyName = new Dictionary<XElement, string>();
var filePathToTextBufferMap = new Dictionary<string, ITextBuffer>();
int projectIdentifier = 0;
int documentIdentifier = 0;
foreach (var projectElement in workspaceElement.Elements(ProjectElementName))
{
var project = CreateProject(
workspaceElement,
projectElement,
exportProvider,
workspace,
projectElementToAssemblyName,
documentElementToFilePath,
filePathToTextBufferMap,
ref projectIdentifier,
ref documentIdentifier);
Assert.False(projectMap.ContainsKey(project.AssemblyName));
projectMap.Add(project.AssemblyName, project);
workspace.Projects.Add(project);
}
var documentFilePaths = new HashSet<string>();
foreach (var project in projectMap.Values)
{
foreach (var document in project.Documents)
{
Assert.True(document.IsLinkFile || documentFilePaths.Add(document.FilePath));
}
}
var submissions = CreateSubmissions(workspace, workspaceElement.Elements(SubmissionElementName), exportProvider);
foreach (var submission in submissions)
{
projectMap.Add(submission.AssemblyName, submission);
}
var solution = new TestHostSolution(projectMap.Values.ToArray());
workspace.AddTestSolution(solution);
foreach (var projectElement in workspaceElement.Elements(ProjectElementName))
{
foreach (var projectReference in projectElement.Elements(ProjectReferenceElementName))
{
var fromName = projectElementToAssemblyName[projectElement];
var toName = projectReference.Value;
var fromProject = projectMap[fromName];
var toProject = projectMap[toName];
var aliases = projectReference.Attributes(AliasAttributeName).Select(a => a.Value).ToImmutableArray();
workspace.OnProjectReferenceAdded(fromProject.Id, new ProjectReference(toProject.Id, aliases.Any() ? aliases : default(ImmutableArray<string>)));
}
}
for (int i = 1; i < submissions.Count; i++)
{
if (submissions[i].CompilationOptions == null)
{
continue;
}
for (int j = i - 1; j >= 0; j--)
{
if (submissions[j].CompilationOptions != null)
{
workspace.OnProjectReferenceAdded(submissions[i].Id, new ProjectReference(submissions[j].Id));
break;
}
}
}
foreach (var project in projectMap.Values)
{
foreach (var document in project.Documents)
{
if (openDocuments)
{
workspace.OnDocumentOpened(document.Id, document.GetOpenTextContainer(), isCurrentContext: !document.IsLinkFile);
}
//.........这里部分代码省略.........