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


C# AdhocWorkspace.AddDocument方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: TestOpenFileOnlyAnalyzerDiagnostics

        public async Task TestOpenFileOnlyAnalyzerDiagnostics()
        {
            var workspace = new AdhocWorkspace();

            var project = workspace.AddProject(
                           ProjectInfo.Create(
                               ProjectId.CreateNewId(),
                               VersionStamp.Create(),
                               "CSharpProject",
                               "CSharpProject",
                               LanguageNames.CSharp));

            var document = workspace.AddDocument(project.Id, "Empty.cs", SourceText.From(""));

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

            // listen to events
            service.DiagnosticsUpdated += (s, a) =>
            {
                if (workspace.IsDocumentOpen(a.DocumentId))
                {
                    // check the diagnostics are reported
                    Assert.Equal(document.Id, a.DocumentId);
                    Assert.Equal(1, a.Diagnostics.Length);
                    Assert.Equal(OpenFileOnlyAnalyzer.s_syntaxRule.Id, a.Diagnostics[0].Id);
                }

                if (a.DocumentId == document.Id && !workspace.IsDocumentOpen(a.DocumentId))
                {
                    // check the diagnostics reported are cleared
                    Assert.Equal(0, a.Diagnostics.Length);
                }
            };

            // open document
            workspace.OpenDocument(document.Id);
            await analyzer.DocumentOpenAsync(document, CancellationToken.None).ConfigureAwait(false);

            // cause analysis
            await RunAllAnalysisAsync(analyzer, document).ConfigureAwait(false);

            // close document
            workspace.CloseDocument(document.Id);
            await analyzer.DocumentCloseAsync(document, CancellationToken.None).ConfigureAwait(false);

            await RunAllAnalysisAsync(analyzer, document).ConfigureAwait(false);

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

示例5: GetDocumentFromIncompleteProject

        private static Document GetDocumentFromIncompleteProject(AdhocWorkspace workspace)
        {
            var project = workspace.AddProject(
                            ProjectInfo.Create(
                                ProjectId.CreateNewId(),
                                VersionStamp.Create(),
                                "CSharpProject",
                                "CSharpProject",
                                LanguageNames.CSharp).WithHasAllInformation(hasAllInformation: false));

            return workspace.AddDocument(project.Id, "Empty.cs", SourceText.From(""));
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:12,代码来源:DiagnosticAnalyzerServiceTests.cs

示例6: TestUpdateCSharpLanguageVersionAsync

        public async Task TestUpdateCSharpLanguageVersionAsync()
        {
            using (var ws = new AdhocWorkspace())
            {
                var projid = ws.AddProject("TestProject", LanguageNames.CSharp).Id;
                var docid1 = ws.AddDocument(projid, "A.cs", SourceText.From("public class A { }")).Id;
                var docid2 = ws.AddDocument(projid, "B.cs", SourceText.From("public class B { }")).Id;

                var pws = new WorkspaceWithPartialSemantics(ws.CurrentSolution);
                var proj = pws.CurrentSolution.GetProject(projid);
                var comp = await proj.GetCompilationAsync();

                // change language version
                var parseOptions = proj.ParseOptions as CS.CSharpParseOptions;
                pws.SetParseOptions(projid, parseOptions.WithLanguageVersion(CS.LanguageVersion.CSharp3));

                // get partial semantics doc
                var frozen = await pws.CurrentSolution.GetDocument(docid1).WithFrozenPartialSemanticsAsync(CancellationToken.None);
            }
        }
开发者ID:GuilhermeSa,项目名称:roslyn,代码行数:20,代码来源:AdhocWorkspaceTests.cs


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