本文整理汇总了C#中Microsoft.CodeAnalysis.AdhocWorkspace.WithDocumentText方法的典型用法代码示例。如果您正苦于以下问题:C# AdhocWorkspace.WithDocumentText方法的具体用法?C# AdhocWorkspace.WithDocumentText怎么用?C# AdhocWorkspace.WithDocumentText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.AdhocWorkspace
的用法示例。
在下文中一共展示了AdhocWorkspace.WithDocumentText方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGetProjectForAssemblySymbol
public void TestGetProjectForAssemblySymbol()
{
var pid1 = ProjectId.CreateNewId("p1");
var pid2 = ProjectId.CreateNewId("p2");
var pid3 = ProjectId.CreateNewId("p3");
var did1 = DocumentId.CreateNewId(pid1);
var did2 = DocumentId.CreateNewId(pid2);
var did3 = DocumentId.CreateNewId(pid3);
var text1 = @"
Public Class A
End Class";
var text2 = @"
Public Class B
End Class
";
var text3 = @"
public class C : B {
}
";
var text4 = @"
public class C : A {
}
";
var solution = new AdhocWorkspace().CurrentSolution
.AddProject(pid1, "FooA", "Foo.dll", LanguageNames.VisualBasic)
.AddDocument(did1, "A.vb", text1)
.AddMetadataReference(pid1, s_mscorlib)
.AddProject(pid2, "FooB", "Foo2.dll", LanguageNames.VisualBasic)
.AddDocument(did2, "B.vb", text2)
.AddMetadataReference(pid2, s_mscorlib)
.AddProject(pid3, "Bar", "Bar.dll", LanguageNames.CSharp)
.AddDocument(did3, "C.cs", text3)
.AddMetadataReference(pid3, s_mscorlib)
.AddProjectReference(pid3, new ProjectReference(pid1))
.AddProjectReference(pid3, new ProjectReference(pid2));
var project3 = solution.GetProject(pid3);
var comp3 = project3.GetCompilationAsync().Result;
var classC = comp3.GetTypeByMetadataName("C");
var projectForBaseType = solution.GetProject(classC.BaseType.ContainingAssembly);
Assert.Equal(pid2, projectForBaseType.Id);
// switch base type to A then try again
var solution2 = solution.WithDocumentText(did3, SourceText.From(text4));
project3 = solution2.GetProject(pid3);
comp3 = project3.GetCompilationAsync().Result;
classC = comp3.GetTypeByMetadataName("C");
projectForBaseType = solution2.GetProject(classC.BaseType.ContainingAssembly);
Assert.Equal(pid1, projectForBaseType.Id);
}