本文整理汇总了C#中AdhocWorkspace类的典型用法代码示例。如果您正苦于以下问题:C# AdhocWorkspace类的具体用法?C# AdhocWorkspace怎么用?C# AdhocWorkspace使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AdhocWorkspace类属于命名空间,在下文中一共展示了AdhocWorkspace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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);
}
}
示例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);
}
}
示例4: TestPreviewCreationWithSolution
public void TestPreviewCreationWithSolution()
{
using (var custom = new AdhocWorkspace())
using (var previewWorkspace = new PreviewWorkspace(custom.CurrentSolution))
{
Assert.NotNull(previewWorkspace.CurrentSolution);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
});
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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());
}
}
示例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);
}
}
示例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;
}
示例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);
}
}