本文整理汇总了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);
}
}
示例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);
}
}
示例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());
}
}
示例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);
}
示例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(""));
}
示例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);
}
}