本文整理汇总了C#中Microsoft.CodeAnalysis.ProjectState类的典型用法代码示例。如果您正苦于以下问题:C# ProjectState类的具体用法?C# ProjectState怎么用?C# ProjectState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProjectState类属于Microsoft.CodeAnalysis命名空间,在下文中一共展示了ProjectState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Project
internal Project(Solution solution, ProjectState projectState)
{
Contract.ThrowIfNull(solution);
Contract.ThrowIfNull(projectState);
_solution = solution;
_projectState = projectState;
}
示例2: CompilationTracker
private CompilationTracker(
ProjectState project,
State state)
{
Contract.ThrowIfNull(project);
this.ProjectState = project;
this.stateDoNotAccessDirectly = state;
}
示例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;
}
示例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);
}
示例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();
}
示例6: IsSameLanguage
public static bool IsSameLanguage(ProjectState project1, ProjectState project2)
{
return project1.LanguageServices == project2.LanguageServices;
}
示例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;
}
示例8: LogBuildCompilationAsync
private static string LogBuildCompilationAsync(ProjectState state)
{
return string.Join(",", state.AssemblyName, state.DocumentIds.Count);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例13: GetSourceCodeKind
private static SourceCodeKind GetSourceCodeKind(ProjectState project)
{
return project.ParseOptions != null ? project.ParseOptions.Kind : SourceCodeKind.Regular;
}
示例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;
}
}
示例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;
}
}