当前位置: 首页>>代码示例>>C#>>正文


C# TestWorkspace.OnProjectReferenceAdded方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace.OnProjectReferenceAdded方法的典型用法代码示例。如果您正苦于以下问题:C# TestWorkspace.OnProjectReferenceAdded方法的具体用法?C# TestWorkspace.OnProjectReferenceAdded怎么用?C# TestWorkspace.OnProjectReferenceAdded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace的用法示例。


在下文中一共展示了TestWorkspace.OnProjectReferenceAdded方法的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);
                    }
//.........这里部分代码省略.........
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:101,代码来源:TestWorkspaceFactory_XmlConsumption.cs


注:本文中的Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace.OnProjectReferenceAdded方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。