當前位置: 首頁>>代碼示例>>C#>>正文


C# CodeAnalysis.ProjectState類代碼示例

本文整理匯總了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;
        }
開發者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


注:本文中的Microsoft.CodeAnalysis.ProjectState類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。