本文整理汇总了C#中Microsoft.CodeAnalysis.ProjectState类的典型用法代码示例。如果您正苦于以下问题:C# ProjectState类的具体用法?C# ProjectState怎么用?C# ProjectState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProjectState类属于Microsoft.CodeAnalysis命名空间,在下文中一共展示了ProjectState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Project
internal Project(Solution solution, ProjectState projectState)
{
Contract.ThrowIfNull(solution);
Contract.ThrowIfNull(projectState);
_solution = solution;
_projectState = projectState;
}
开发者ID:tvsonar,项目名称:roslyn,代码行数:8,代码来源:Project.cs
示例2: CompilationTracker
private CompilationTracker(
ProjectState project,
State state)
{
Contract.ThrowIfNull(project);
this.ProjectState = project;
this.stateDoNotAccessDirectly = state;
}
开发者ID:riversky,项目名称:roslyn,代码行数:9,代码来源:Solution.CompilationTracker.cs
示例3: GetCompilationForMetadataReference
// Hand out the same compilation reference for everyone who asks. Use
// WeakReference<Compilation> so that if no one is using the MetadataReference,
// it can be collected.
internal static Compilation GetCompilationForMetadataReference(ProjectState projectState, Compilation compilation)
{
var weakReference = s_compilationReferenceMap.GetValue(projectState, s_createValue);
Compilation reference;
lock (s_guard)
{
if (!weakReference.TryGetTarget(out reference))
{
reference = compilation.Clone(); // drop all existing symbols
weakReference.SetTarget(reference);
}
}
return reference;
}
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:18,代码来源:MetadataReferenceManager.cs
示例4: AddProject
/// <summary>
/// Create a new solution instance that includes a project with the specified project information.
/// </summary>
public SolutionState AddProject(ProjectInfo projectInfo)
{
if (projectInfo == null)
{
throw new ArgumentNullException(nameof(projectInfo));
}
var projectId = projectInfo.Id;
var language = projectInfo.Language;
if (language == null)
{
throw new ArgumentNullException(nameof(language));
}
var displayName = projectInfo.Name;
if (displayName == null)
{
throw new ArgumentNullException(nameof(displayName));
}
CheckNotContainsProject(projectId);
var languageServices = this.Workspace.Services.GetLanguageServices(language);
if (languageServices == null)
{
throw new ArgumentException(string.Format(WorkspacesResources.The_language_0_is_not_supported, language));
}
var newProject = new ProjectState(projectInfo, languageServices, _solutionServices);
return this.AddProject(newProject.Id, newProject);
}
开发者ID:tvsonar,项目名称:roslyn,代码行数:36,代码来源:SolutionState.cs
示例5: CreateLinkedFilesMapWithAddedDocuments
private ImmutableDictionary<string, ImmutableArray<DocumentId>> CreateLinkedFilesMapWithAddedDocuments(ProjectState projectState, IEnumerable<DocumentId> documentIds)
{
var builder = _linkedFilesMap.ToBuilder();
foreach (var documentId in documentIds)
{
var filePath = projectState.GetDocumentState(documentId).FilePath;
if (string.IsNullOrEmpty(filePath))
{
continue;
}
ImmutableArray<DocumentId> documentIdsWithPath;
builder[filePath] = builder.TryGetValue(filePath, out documentIdsWithPath)
? documentIdsWithPath.Add(documentId)
: ImmutableArray.Create(documentId);
}
return builder.ToImmutable();
}
开发者ID:tvsonar,项目名称:roslyn,代码行数:21,代码来源:SolutionState.cs
示例6: IsSameLanguage
public static bool IsSameLanguage(ProjectState project1, ProjectState project2)
{
return project1.LanguageServices == project2.LanguageServices;
}
开发者ID:riversky,项目名称:roslyn,代码行数:4,代码来源:ProjectState.cs
示例7: GetMetadataReferenceAsync
/// <summary>
/// Get a metadata reference for the project's compilation
/// </summary>
internal async Task<MetadataReference> GetMetadataReferenceAsync(ProjectReference projectReference, ProjectState fromProject, CancellationToken cancellationToken)
{
try
{
// Get the compilation state for this project. If it's not already created, then this
// will create it. Then force that state to completion and get a metadata reference to it.
var tracker = this.GetCompilationTracker(projectReference.ProjectId);
var mdref = await tracker.GetMetadataReferenceAsync(this, fromProject, projectReference, cancellationToken).ConfigureAwait(false);
if (mdref != null)
{
RecordReferencedProject(mdref, projectReference.ProjectId);
}
return mdref;
}
catch (Exception e) if (ExceptionHelpers.CrashUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
/// <summary>
/// Attempt to get the best readily available compilation for the project. It may be a
/// partially built compilation.
/// </summary>
internal MetadataReference GetPartialMetadataReference(
ProjectReference projectReference,
ProjectState fromProject,
CancellationToken cancellationToken)
{
// Try to get the compilation state for this project. If it doesn't exist, don't do any
// more work.
CompilationTracker state;
if (!this.projectIdToTrackerMap.TryGetValue(projectReference.ProjectId, out state))
{
return null;
}
var mdref = state.GetPartialMetadataReference(this, fromProject, projectReference, cancellationToken);
if (mdref != null)
{
RecordReferencedProject(mdref, projectReference.ProjectId);
}
return mdref;
}
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:51,代码来源:Solution.cs
示例8: LogBuildCompilationAsync
private static string LogBuildCompilationAsync(ProjectState state)
{
return string.Join(",", state.AssemblyName, state.DocumentIds.Count);
}
开发者ID:riversky,项目名称:roslyn,代码行数:4,代码来源:Solution.CompilationTracker.cs
示例9: GetMetadataReferenceAsync
/// <summary>
/// Get a metadata reference for the project's compilation
/// </summary>
internal async Task<MetadataReference> GetMetadataReferenceAsync(ProjectReference projectReference, ProjectState fromProject, CancellationToken cancellationToken)
{
// Get the compilation state for this project. If it's not already created, then this
// will create it. Then force that state to completion and get a metadata reference to it.
var tracker = this.GetCompilationTracker(projectReference.ProjectId);
var mdref = await tracker.GetMetadataReferenceAsync(this, fromProject, projectReference, cancellationToken).ConfigureAwait(false);
if (mdref != null)
{
RecordReferencedProject(mdref, projectReference.ProjectId);
}
return mdref;
}
开发者ID:pheede,项目名称:roslyn,代码行数:17,代码来源:Solution.cs
示例10: ForkProject
/// <summary>
/// Creates a new snapshot with an updated project and an action that will produce a new
/// compilation matching the new project out of an old compilation. All dependent projects
/// are fixed-up if the change to the new project affects its public metadata, and old
/// dependent compilations are forgotten.
/// </summary>
private SolutionState ForkProject(
ProjectState newProjectState,
CompilationTranslationAction translate = null,
bool withProjectReferenceChange = false,
ImmutableDictionary<string, ImmutableArray<DocumentId>> newLinkedFilesMap = null,
bool forkTracker = true)
{
var projectId = newProjectState.Id;
var newStateMap = _projectIdToProjectStateMap.SetItem(projectId, newProjectState);
var newDependencyGraph = withProjectReferenceChange ? CreateDependencyGraph(_projectIds, newStateMap) : _dependencyGraph;
var newTrackerMap = CreateCompilationTrackerMap(projectId, newDependencyGraph);
// If we have a tracker for this project, then fork it as well (along with the
// translation action and store it in the tracker map.
CompilationTracker tracker;
if (newTrackerMap.TryGetValue(projectId, out tracker))
{
newTrackerMap = newTrackerMap.Remove(projectId);
if (forkTracker)
{
newTrackerMap = newTrackerMap.Add(projectId, tracker.Fork(newProjectState, translate));
}
}
var modifiedDocumentOnly = translate is CompilationTranslationAction.TouchDocumentAction;
var newLatestProjectVersion = modifiedDocumentOnly ? _lazyLatestProjectVersion : new Lazy<VersionStamp>(() => newProjectState.Version);
return this.Branch(
idToProjectStateMap: newStateMap,
projectIdToTrackerMap: newTrackerMap,
dependencyGraph: newDependencyGraph,
linkedFilesMap: newLinkedFilesMap ?? _linkedFilesMap,
lazyLatestProjectVersion: newLatestProjectVersion);
}
开发者ID:tvsonar,项目名称:roslyn,代码行数:42,代码来源:SolutionState.cs
示例11: ReplaceSyntaxTreesWithTreesFromNewProjectStateAsync
private static async Task<Compilation> ReplaceSyntaxTreesWithTreesFromNewProjectStateAsync(Compilation compilation, ProjectState projectState, CancellationToken cancellationToken)
{
var syntaxTrees = new List<SyntaxTree>(capacity: projectState.DocumentIds.Count);
foreach (var documentState in projectState.OrderedDocumentStates)
{
cancellationToken.ThrowIfCancellationRequested();
syntaxTrees.Add(await documentState.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false));
}
return compilation.RemoveAllSyntaxTrees().AddSyntaxTrees(syntaxTrees);
}
开发者ID:tvsonar,项目名称:roslyn,代码行数:12,代码来源:SolutionState.cs
示例12: ForkProject
/// <summary>
/// Creates a new snapshot with an updated project and an action that will produce a new
/// compilation matching the new project out of an old compilation. All dependent projects
/// are fixed-up if the change to the new project affects its public metadata, and old
/// dependent compilations are forgotten.
/// </summary>
private Solution ForkProject(
ProjectState newProjectState,
CompilationTranslationAction translate = null,
bool withProjectReferenceChange = false,
bool withDocumentListChange = false)
{
// make sure we are getting only known translate actions
CompilationTranslationAction.CheckKnownActions(translate);
var projectId = newProjectState.Id;
var newStateMap = this.projectIdToProjectStateMap.SetItem(projectId, newProjectState);
var newDependencyGraph = withProjectReferenceChange ? CreateDependencyGraph(this.projectIds, newStateMap) : this.dependencyGraph;
var newTrackerMap = CreateCompilationTrackerMap(projectId, newDependencyGraph);
var newLinkedFilesMap = withDocumentListChange
? CreateLinkedFilesMapWithChangedProject(projectIdToProjectStateMap[projectId], newProjectState)
: this.linkedFilesMap;
// If we have a tracker for this project, then fork it as well (along with the
// translation action and store it in the tracker map.
CompilationTracker state;
if (newTrackerMap.TryGetValue(projectId, out state))
{
newTrackerMap = newTrackerMap.Remove(projectId).Add(projectId, state.Fork(newProjectState, translate));
}
var modifiedDocumentOnly = translate is CompilationTranslationAction.TouchDocumentAction;
var newLatestProjectVersion = modifiedDocumentOnly ? this.lazyLatestProjectVersion : new Lazy<VersionStamp>(() => newProjectState.Version);
return this.Branch(
idToProjectStateMap: newStateMap,
projectIdToTrackerMap: newTrackerMap,
dependencyGraph: newDependencyGraph,
linkedFilesMap: newLinkedFilesMap,
lazyLatestProjectVersion: newLatestProjectVersion);
}
开发者ID:pheede,项目名称:roslyn,代码行数:42,代码来源:Solution.cs
示例13: GetSourceCodeKind
private static SourceCodeKind GetSourceCodeKind(ProjectState project)
{
return project.ParseOptions != null ? project.ParseOptions.Kind : SourceCodeKind.Regular;
}
开发者ID:Rickinio,项目名称:roslyn,代码行数:4,代码来源:Solution.cs
示例14: GetMetadataReferenceAsync
/// <summary>
/// Get a metadata reference to this compilation info's compilation with respect to
/// another project. For cross language references produce a skeletal assembly. If the
/// compilation is not available, it is built. If a skeletal assembly reference is
/// needed and does not exist, it is also built.
/// </summary>
public async Task<MetadataReference> GetMetadataReferenceAsync(
SolutionState solution,
ProjectState fromProject,
ProjectReference projectReference,
CancellationToken cancellationToken)
{
try
{
// if we already have the compilation and its right kind then use it.
if (this.ProjectState.LanguageServices == fromProject.LanguageServices
&& this.TryGetCompilation(out var compilation))
{
return compilation.ToMetadataReference(projectReference.Aliases, projectReference.EmbedInteropTypes);
}
// If same language then we can wrap the other project's compilation into a compilation reference
if (this.ProjectState.LanguageServices == fromProject.LanguageServices)
{
// otherwise, base it off the compilation by building it first.
compilation = await this.GetCompilationAsync(solution, cancellationToken).ConfigureAwait(false);
return compilation.ToMetadataReference(projectReference.Aliases, projectReference.EmbedInteropTypes);
}
else
{
// otherwise get a metadata only image reference that is built by emitting the metadata from the referenced project's compilation and re-importing it.
return await this.GetMetadataOnlyImageReferenceAsync(solution, projectReference, cancellationToken).ConfigureAwait(false);
}
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
开发者ID:TyOverby,项目名称:roslyn,代码行数:40,代码来源:SolutionState.CompilationTracker.cs
示例15: GetMetadataReferenceAsync
/// <summary>
/// Get a metadata reference for the project's compilation
/// </summary>
internal async Task<MetadataReference> GetMetadataReferenceAsync(ProjectReference projectReference, ProjectState fromProject, CancellationToken cancellationToken)
{
try
{
// Get the compilation state for this project. If it's not already created, then this
// will create it. Then force that state to completion and get a metadata reference to it.
var tracker = this.GetCompilationTracker(projectReference.ProjectId);
var mdref = await tracker.GetMetadataReferenceAsync(this, fromProject, projectReference, cancellationToken).ConfigureAwait(false);
if (mdref != null)
{
RecordReferencedProject(mdref, projectReference.ProjectId);
}
return mdref;
}
catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
{
throw ExceptionUtilities.Unreachable;
}
}
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:24,代码来源:Solution.cs
示例16: GetPartialMetadataReference
/// <summary>
/// Attempt to get the best readily available compilation for the project. It may be a
/// partially built compilation.
/// </summary>
internal MetadataReference GetPartialMetadataReference(
ProjectReference projectReference,
ProjectState fromProject,
CancellationToken cancellationToken)
{
// Try to get the compilation state for this project. If it doesn't exist, don't do any
// more work.
CompilationTracker state;
if (!this.projectIdToTrackerMap.TryGetValue(projectReference.ProjectId, out state))
{
return null;
}
var mdref = state.GetPartialMetadataReference(this, fromProject, projectReference, cancellationToken);
if (mdref != null)
{
RecordReferencedProject(mdref, projectReference.ProjectId);
}
return mdref;
}
开发者ID:pheede,项目名称:roslyn,代码行数:26,代码来源:Solution.cs
示例17: CreateLinkedFilesMapWithRemovedProject
private ImmutableDictionary<string, ImmutableArray<DocumentId>> CreateLinkedFilesMapWithRemovedProject(ProjectState projectState)
{
return CreateLinkedFilesMapWithRemovedDocuments(projectState, projectState.DocumentIds);
}
开发者ID:tvsonar,项目名称:roslyn,代码行数:4,代码来源:SolutionState.cs
示例18: GetCompilationAsync
/// <summary>
/// Returns the compilation for the specified <see cref="ProjectState"/>. Can return <code>null</code> when the project
/// does not support compilations.
/// </summary>
public Task<Compilation> GetCompilationAsync(ProjectState project, CancellationToken cancellationToken)
{
return project.SupportsCompilation
? this.GetCompilationTracker(project.Id).GetCompilationAsync(this, cancellationToken)
: SpecializedTasks.Default<Compilation>();
}
开发者ID:tvsonar,项目名称:roslyn,代码行数:10,代码来源:SolutionState.cs
示例19: CreateLinkedFilesMapWithRemovedDocuments
private ImmutableDictionary<string, ImmutableArray<DocumentId>> CreateLinkedFilesMapWithRemovedDocuments(
ProjectState projectState,
IEnumerable<DocumentId> documentIds)
{
var builder = _linkedFilesMap.ToBuilder();
foreach (var documentId in documentIds)
{
var filePath = projectState.GetDocumentState(documentId).FilePath;
if (string.IsNullOrEmpty(filePath))
{
continue;
}
ImmutableArray<DocumentId> documentIdsWithPath;
if (!builder.TryGetValue(filePath, out documentIdsWithPath) || !documentIdsWithPath.Contains(documentId))
{
throw new ArgumentException("The given documentId was not found in the linkedFilesMap.");
}
if (documentIdsWithPath.Length == 1)
{
builder.Remove(filePath);
}
else
{
builder[filePath] = documentIdsWithPath.Remove(documentId);
}
}
return builder.ToImmutable();
}
开发者ID:tvsonar,项目名称:roslyn,代码行数:33,代码来源:SolutionState.cs
示例20: GetPartialCompilationState
/// <summary>
/// Tries to get the latest snapshot of the compilation without waiting for it to be
/// fully built. This method takes advantage of the progress side-effect produced during
/// BuildCompilation. It will either return the already built compilation, any
/// in-progress compilation or any known old compilation in that order of preference.
/// The compilation state that is returned will have a compilation that is retained so
/// that it cannot disappear.
/// </summary>
private void GetPartialCompilationState(
Solution solution,
DocumentId id,
out ProjectState inProgressProject,
out Compilation inProgressCompilation,
CancellationToken cancellationToken)
{
var state = this.ReadState();
inProgressCompilation = state.Compilation.GetValue(cancellationToken);
// check whether we can bail out quickly for typing case
var inProgressState = state as InProgressState;
// all changes left for this document is modifying the given document.
// we can use current state as it is since we will replace the document with latest document anyway.
if (inProgressState != null &&
inProgressCompilation != null &&
inProgressState.IntermediateProjects.All(t => TouchDocumentActionForDocument(t, id)))
{
inProgressProject = this.ProjectState;
return;
}
inProgressProject = inProgressState != null ? inProgressState.IntermediateProjects.First().Item1 : this.ProjectState;
// if we already have a final compilation we are done.
if (inProgressCompilation != null && state is FinalState)
{
return;
}
// 1) if we have an in-progress compilation use it.
// 2) If we don't, then create a simple empty compilation/project.
// 3) then, make sure that all it's p2p refs and whatnot are correct.
if (inProgressCompilation == null)
{
inProgressProject = inProgressProject.RemoveAllDocuments();
inProgressCompilation = this.CreateEmptyCompilation(solution);
}
// first remove all project from the project and compilation.
inProgressProject = inProgressProject.WithProjectReferences(ImmutableList.Create<ProjectReference>());
// Now add in back a consistent set of project references. For project references
// try to get either a CompilationReference or a SkeletonReference. This ensures
// that the in-progress project only reports a reference to another project if it
// could actually get a reference to that project's metadata.
var metadataReferences = new List<MetadataReference>();
var newProjectReferences = new List<ProjectReference>();
metadataReferences.AddRange(this.ProjectState.MetadataReferences);
foreach (var projectReference in this.ProjectState.ProjectReferences)
{
var referencedProject = solution.GetProject(projectReference.ProjectId);
if (referencedProject != null)
{
if (referencedProject.IsSubmission)
{
var compilation = solution.GetCompilationAsync(projectReference.ProjectId, cancellationToken).WaitAndGetResult(cancellationToken);
inProgressCompilation = inProgressCompilation.WithPreviousSubmission(compilation);
}
else
{
// get the latest metadata for the partial compilation of the referenced project.
var metadata = solution.GetPartialMetadataReference(projectReference, this.ProjectState, cancellationToken);
if (metadata == null)
{
// if we failed to get the metadata, check to see if we previously had existing metadata and reuse it instead.
metadata = inProgressCompilation.References.FirstOrDefault(r => solution.GetProjectId(r) == projectReference.ProjectId);
}
if (metadata != null)
{
newProjectReferences.Add(projectReference);
metadataReferences.Add(metadata);
}
}
}
}
inProgressProject = inProgressProject.AddProjectReferences(newProjectReferences);
if (!Enumerable.SequenceEqual(inProgressCompilation.References, metadataReferences))
{
inProgressCompilation = inProgressCompilation.WithReferences(metadataReferences);
}
}
开发者ID:riversky,项目名称:roslyn,代码行数:95,代码来源:Solution.CompilationTracker.cs
注:本文中的Microsoft.CodeAnalysis.ProjectState类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论