• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# AdhocWorkspace类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中AdhocWorkspace的典型用法代码示例。如果您正苦于以下问题:C# AdhocWorkspace类的具体用法?C# AdhocWorkspace怎么用?C# AdhocWorkspace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AdhocWorkspace类属于命名空间,在下文中一共展示了AdhocWorkspace类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TestAddSolution_SolutionInfo

        public void TestAddSolution_SolutionInfo()
        {
            using (var ws = new AdhocWorkspace())
            {
                var pinfo = ProjectInfo.Create(
                        ProjectId.CreateNewId(),
                        version: VersionStamp.Default,
                        name: "TestProject",
                        assemblyName: "TestProject.dll",
                        language: LanguageNames.CSharp);

                var sinfo = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Default, projects: new ProjectInfo[] { pinfo });

                var solution = ws.AddSolution(sinfo);

                Assert.Same(ws.CurrentSolution, solution);
                Assert.Equal(solution.Id, sinfo.Id);

                Assert.Equal(sinfo.Projects.Count, solution.ProjectIds.Count);
                var project = solution.Projects.FirstOrDefault();
                Assert.NotNull(project);
                Assert.Equal(pinfo.Name, project.Name);
                Assert.Equal(pinfo.Id, project.Id);
                Assert.Equal(pinfo.AssemblyName, project.AssemblyName);
                Assert.Equal(pinfo.Language, project.Language);
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:27,代码来源:AdhocWorkspaceTests.cs


示例2: CheckPEReferencesSameAfterSolutionChangedTest

        public async Task CheckPEReferencesSameAfterSolutionChangedTest()
        {
            using (var ws = new AdhocWorkspace())
            {
                var projectInfo = ProjectInfo.Create(
                    ProjectId.CreateNewId(),
                    VersionStamp.Create(),
                    "TestProject",
                    "TestProject",
                    LanguageNames.CSharp,
                    metadataReferences: ImmutableArray.Create<MetadataReference>(PortableExecutableReference.CreateFromFile(typeof(object).Assembly.Location)));

                var project = ws.AddProject(projectInfo);

                // get original references
                var compilation1 = await project.GetCompilationAsync();
                var references1 = compilation1.ExternalReferences;

                // just some arbitary action to create new snpahost that doesnt affect references
                var info = DocumentInfo.Create(DocumentId.CreateNewId(project.Id), "code.cs");
                var document = ws.AddDocument(info);

                // get new compilation
                var compilation2 = await document.Project.GetCompilationAsync();
                var references2 = compilation2.ExternalReferences;

                Assert.Equal(references1, references2);
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:29,代码来源:WorkspaceReferenceTests.cs


示例3: Test

        internal void Test(
            Func<SyntaxGenerator, SyntaxNode> nodeCreator,
            string cs, string vb)
        {
            var hostServices = MefV1HostServices.Create(TestExportProvider.ExportProviderWithCSharpAndVisualBasic.AsExportProvider());
            var workspace = new AdhocWorkspace(hostServices);

            if (cs != null)
            {
                var csharpCodeGenService = workspace.Services.GetLanguageServices(LanguageNames.CSharp).GetService<ICodeGenerationService>();
                var codeDefFactory = workspace.Services.GetLanguageServices(LanguageNames.CSharp).GetService<SyntaxGenerator>();

                var node = nodeCreator(codeDefFactory);
                node = node.NormalizeWhitespace();
                TokenUtilities.AssertTokensEqual(cs, node.ToFullString(), LanguageNames.CSharp);
            }

            if (vb != null)
            {
                var visualBasicCodeGenService = workspace.Services.GetLanguageServices(LanguageNames.VisualBasic).GetService<ICodeGenerationService>();
                var codeDefFactory = workspace.Services.GetLanguageServices(LanguageNames.VisualBasic).GetService<SyntaxGenerator>();

                var node = nodeCreator(codeDefFactory);
                node = node.NormalizeWhitespace();
                TokenUtilities.AssertTokensEqual(vb, node.ToString(), LanguageNames.VisualBasic);
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:27,代码来源:AbstractCodeGenerationTests.cs


示例4: TestPreviewCreationWithSolution

 public void TestPreviewCreationWithSolution()
 {
     using (var custom = new AdhocWorkspace())
     using (var previewWorkspace = new PreviewWorkspace(custom.CurrentSolution))
     {
         Assert.NotNull(previewWorkspace.CurrentSolution);
     }
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:8,代码来源:PreviewWorkspaceTests.cs


示例5: TestDefaultCompositionIncludesFeaturesLayer

        public void TestDefaultCompositionIncludesFeaturesLayer()
        {
            var ws = new AdhocWorkspace();

            var csservice = ws.Services.GetLanguageServices(LanguageNames.CSharp).GetService<Microsoft.CodeAnalysis.Completion.CompletionService>();
            Assert.NotNull(csservice);

            var vbservice = ws.Services.GetLanguageServices(LanguageNames.VisualBasic).GetService<Microsoft.CodeAnalysis.Completion.CompletionService>();
            Assert.NotNull(vbservice);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:10,代码来源:WorkspaceTests.cs


示例6: TestAddProject_NameAndLanguage

 public void TestAddProject_NameAndLanguage()
 {
     using (var ws = new AdhocWorkspace())
     {
         var project = ws.AddProject("TestProject", LanguageNames.CSharp);
         Assert.Same(project, ws.CurrentSolution.Projects.FirstOrDefault());
         Assert.Equal("TestProject", project.Name);
         Assert.Equal(LanguageNames.CSharp, project.Language);
     }
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:10,代码来源:AdhocWorkspaceTests.cs


示例7: CreateSolutionSnapshotId_Empty_Serialization

        public async Task CreateSolutionSnapshotId_Empty_Serialization()
        {
            var solution = new AdhocWorkspace().CurrentSolution;

            var snapshotService = (new SolutionChecksumServiceFactory()).CreateService(solution.Workspace.Services) as ISolutionChecksumService;
            using (var snapshot = await snapshotService.CreateChecksumAsync(solution, CancellationToken.None).ConfigureAwait(false))
            {
                await VerifySnapshotSerializationAsync(snapshotService, solution, snapshot.SolutionChecksum).ConfigureAwait(false);
            }
        }
开发者ID:natidea,项目名称:roslyn,代码行数:10,代码来源:SnapshotSerializationTests.cs


示例8: TestCreateWithoutRequiredServices

        public void TestCreateWithoutRequiredServices()
        {
            string commandLine = @"foo.cs";

            Assert.Throws<InvalidOperationException>(delegate
            {
                var ws = new AdhocWorkspace(); // only includes portable services
                var info = CommandLineProject.CreateProjectInfo("TestProject", LanguageNames.CSharp, commandLine, @"C:\ProjectDirectory", ws);
            });
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:10,代码来源:CommandLineProjectTests.cs


示例9: AcquireCompletionService

        public void AcquireCompletionService()
        {
            var workspace = new AdhocWorkspace();

            var document = workspace
                .AddProject("TestProject", LanguageNames.CSharp)
                .AddDocument("TestDocument.cs", "");

            var service = CompletionService.GetService(document);
            Assert.NotNull(service);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:11,代码来源:CompletionServiceTests.cs


示例10: CreateSolutionSnapshotId_Project_Serialization

        public async Task CreateSolutionSnapshotId_Project_Serialization()
        {
            var solution = new AdhocWorkspace().CurrentSolution;
            var project = solution.AddProject("Project", "Project.dll", LanguageNames.CSharp);

            var snapshotService = (new SolutionChecksumServiceFactory()).CreateService(solution.Workspace.Services) as ISolutionChecksumService;
            using (var snapshot = await snapshotService.CreateChecksumAsync(project.Solution, CancellationToken.None).ConfigureAwait(false))
            {
                await VerifySnapshotSerializationAsync(snapshotService, solution, snapshot.SolutionChecksum).ConfigureAwait(false);
            }
        }
开发者ID:natidea,项目名称:roslyn,代码行数:11,代码来源:SnapshotSerializationTests.cs


示例11: TestAddDocument_DocumentInfo

        public void TestAddDocument_DocumentInfo()
        {
            using (var ws = new AdhocWorkspace())
            {
                var project = ws.AddProject("TestProject", LanguageNames.CSharp);
                var info = DocumentInfo.Create(DocumentId.CreateNewId(project.Id), "code.cs");
                var doc = ws.AddDocument(info);

                Assert.Equal(ws.CurrentSolution.GetDocument(info.Id), doc);
                Assert.Equal(info.Name, doc.Name);
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:12,代码来源:AdhocWorkspaceTests.cs


示例12: TestAddDocument_NameAndText

        public void TestAddDocument_NameAndText()
        {
            using (var ws = new AdhocWorkspace())
            {
                var project = ws.AddProject("TestProject", LanguageNames.CSharp);
                var name = "code.cs";
                var source = "class C {}";
                var doc = ws.AddDocument(project.Id, name, SourceText.From(source));

                Assert.Equal(name, doc.Name);
                Assert.Equal(source, doc.GetTextAsync().Result.ToString());
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:13,代码来源:AdhocWorkspaceTests.cs


示例13: CreateSolutionSnapshotId_Empty

        public async Task CreateSolutionSnapshotId_Empty()
        {
            var solution = new AdhocWorkspace().CurrentSolution;

            var snapshotService = (new SolutionChecksumServiceFactory()).CreateService(solution.Workspace.Services) as ISolutionChecksumService;
            using (var snapshot = await snapshotService.CreateChecksumAsync(solution, CancellationToken.None).ConfigureAwait(false))
            {
                var solutionId = snapshot.SolutionChecksum;
                VerifyChecksumObjectInService(snapshotService, solutionId);
                VerifyChecksumInService(snapshotService, solutionId.Info, WellKnownChecksumObjects.SolutionChecksumObjectInfo);
                VerifyChecksumObjectInService(snapshotService, solutionId.Projects);

                Assert.Equal(solutionId.Projects.Count, 0);
            }
        }
开发者ID:natidea,项目名称:roslyn,代码行数:15,代码来源:SnapshotSerializationTests.cs


示例14: GetSolution

        private Solution GetSolution(params string[] sources)
        {
            var ws = new AdhocWorkspace();
            var pid = ProjectId.CreateNewId();

            var docs = sources.Select((s, i) =>
                DocumentInfo.Create(
                    DocumentId.CreateNewId(pid),
                    name: "code" + i,
                    loader: TextLoader.From(TextAndVersion.Create(SourceText.From(s), VersionStamp.Default)))).ToList();

            var proj = ProjectInfo.Create(pid, VersionStamp.Default, "test", "test.dll", LanguageNames.CSharp, documents: docs,
                metadataReferences: new[] { TestReferences.NetFx.v4_0_30319.mscorlib });

            return ws.AddProject(proj).Solution;
        }
开发者ID:ralfkang,项目名称:roslyn,代码行数:16,代码来源:SymbolEditorTests.cs


示例15: CreateSolutionSnapshotId_Project

        public async Task CreateSolutionSnapshotId_Project()
        {
            var solution = new AdhocWorkspace().CurrentSolution;
            var project = solution.AddProject("Project", "Project.dll", LanguageNames.CSharp);

            var snapshotService = (new SolutionChecksumServiceFactory()).CreateService(solution.Workspace.Services) as ISolutionChecksumService;
            using (var snapshot = await snapshotService.CreateChecksumAsync(project.Solution, CancellationToken.None).ConfigureAwait(false))
            {
                var solutionId = snapshot.SolutionChecksum;
                VerifyChecksumObjectInService(snapshotService, solutionId);
                VerifyChecksumInService(snapshotService, solutionId.Info, WellKnownChecksumObjects.SolutionChecksumObjectInfo);
                VerifyChecksumObjectInService(snapshotService, solutionId.Projects);

                Assert.Equal(solutionId.Projects.Count, 1);
                VerifySnapshotInService(snapshotService, solutionId.Projects.ToProjectObjects(snapshotService)[0], 0, 0, 0, 0, 0);
            }
        }
开发者ID:natidea,项目名称:roslyn,代码行数:17,代码来源:SnapshotSerializationTests.cs


示例16: TestHasSuccessfullyLoadedBeingFalseWhenFileOpened

        public async Task TestHasSuccessfullyLoadedBeingFalseWhenFileOpened()
        {
            var workspace = new AdhocWorkspace();
            var document = GetDocumentFromIncompleteProject(workspace);

            // open document
            workspace.OpenDocument(document.Id);

            // create listener/service/analyzer
            var listener = new AsynchronousOperationListener();
            var service = new MyDiagnosticAnalyzerService(new Analyzer(), listener);
            var analyzer = service.CreateIncrementalAnalyzer(workspace);

            bool syntax = false;
            bool semantic = false;

            // listen to events
            service.DiagnosticsUpdated += (s, a) =>
            {
                switch (a.Diagnostics.Length)
                {
                    case 0:
                        return;
                    case 1:
                        syntax |= a.Diagnostics[0].Id == Analyzer.s_syntaxRule.Id;
                        semantic |= a.Diagnostics[0].Id == Analyzer.s_semanticRule.Id;
                        return;
                    default:
                        AssertEx.Fail("shouldn't reach here");
                        return;
                }
            };

            // now call each analyze method. none of them should run.
            await analyzer.AnalyzeSyntaxAsync(document, InvocationReasons.Empty, CancellationToken.None).ConfigureAwait(false);
            await analyzer.AnalyzeDocumentAsync(document, bodyOpt: null, reasons: InvocationReasons.Empty, cancellationToken: CancellationToken.None).ConfigureAwait(false);
            await analyzer.AnalyzeProjectAsync(document.Project, semanticsChanged: true, reasons: InvocationReasons.Empty, cancellationToken: CancellationToken.None).ConfigureAwait(false);

            // wait for all events to raised
            await listener.CreateWaitTask().ConfigureAwait(false);

            // two should have been called.
            Assert.True(syntax);
            Assert.True(semantic);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:45,代码来源:DiagnosticAnalyzerServiceTests.cs


示例17: TestAddProject_ProjectInfo

        public void TestAddProject_ProjectInfo()
        {
            var info = ProjectInfo.Create(
                ProjectId.CreateNewId(),
                version: VersionStamp.Default,
                name: "TestProject",
                assemblyName: "TestProject.dll",
                language: LanguageNames.CSharp);

            using (var ws = new AdhocWorkspace())
            {
                var project = ws.AddProject(info);
                Assert.Equal(project, ws.CurrentSolution.Projects.FirstOrDefault());
                Assert.Equal(info.Name, project.Name);
                Assert.Equal(info.Id, project.Id);
                Assert.Equal(info.AssemblyName, project.AssemblyName);
                Assert.Equal(info.Language, project.Language);
            }
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:19,代码来源:AdhocWorkspaceTests.cs


示例18: AcquireCompletionService

        public void AcquireCompletionService()
        {
            var hostServices = MefHostServices.Create(
                MefHostServices.DefaultAssemblies.Concat(
                    new[]
                    {
                        typeof(CompletionService).Assembly,
                        typeof(CSharpCompletionService).Assembly
                    }));

            var workspace = new AdhocWorkspace(hostServices);

            var document = workspace
                .AddProject("TestProject", LanguageNames.CSharp)
                .AddDocument("TestDocument.cs", "");

            var service = CompletionService.GetService(document);
            Assert.NotNull(service);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:19,代码来源:CompletionServiceTests.cs


示例19: TestHasSuccessfullyLoadedBeingFalse

        public async Task TestHasSuccessfullyLoadedBeingFalse()
        {
            var workspace = new AdhocWorkspace();
            var document = GetDocumentFromIncompleteProject(workspace);

            // create listener/service/analyzer
            var listener = new AsynchronousOperationListener();
            var service = new MyDiagnosticAnalyzerService(new Analyzer(), listener);
            var analyzer = service.CreateIncrementalAnalyzer(workspace);

            // listen to events
            // check empty since this could be called to clear up existing diagnostics
            service.DiagnosticsUpdated += (s, a) => Assert.Empty(a.Diagnostics);

            // now call each analyze method. none of them should run.
            await RunAllAnalysisAsync(analyzer, document).ConfigureAwait(false);

            // wait for all events to raised
            await listener.CreateWaitTask().ConfigureAwait(false);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:20,代码来源:DiagnosticAnalyzerServiceTests.cs


示例20: TestLinkedFileSet

        public void TestLinkedFileSet(string startText, List<string> updatedTexts, string expectedMergedText, string languageName)
        {
            using (var workspace = new AdhocWorkspace())
            {
                var solution = workspace.CurrentSolution;
                var startSourceText = SourceText.From(startText);
                var documentIds = new List<DocumentId>();

                for (int i = 0; i < updatedTexts.Count; i++)
                {
                    var projectId = ProjectId.CreateNewId();
                    var documentId = DocumentId.CreateNewId(projectId);
                    documentIds.Add(documentId);

                    var projectInfo = ProjectInfo.Create(projectId, VersionStamp.Create(), "ProjectName" + i, "AssemblyName" + i, languageName);

                    solution = solution
                        .AddProject(projectInfo)
                        .AddDocument(documentId, "DocumentName", startSourceText, filePath: "FilePath");
                }

                var startingSolution = solution;
                var updatedSolution = solution;

                for (int i = 0; i < updatedTexts.Count; i++)
                {
                    var text = updatedTexts[i];
                    if (text != startText)
                    {
                        updatedSolution = updatedSolution
                            .WithDocumentText(documentIds[i], SourceText.From(text));
                    }
                }

                var mergedSolution = updatedSolution.WithMergedLinkedFileChangesAsync(startingSolution).Result;
                for (int i = 0; i < updatedTexts.Count; i++)
                {
                    Assert.Equal(expectedMergedText, mergedSolution.GetDocument(documentIds[i]).GetTextAsync().Result.ToString());
                }
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:41,代码来源:LinkedFileDiffMergingTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# AdjacencyGraph类代码示例发布时间:2022-05-24
下一篇:
C# AddressValidator类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap