当前位置: 首页>>代码示例>>C#>>正文


C# Project.GetSemanticVersionAsync方法代码示例

本文整理汇总了C#中Project.GetSemanticVersionAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Project.GetSemanticVersionAsync方法的具体用法?C# Project.GetSemanticVersionAsync怎么用?C# Project.GetSemanticVersionAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Project的用法示例。


在下文中一共展示了Project.GetSemanticVersionAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadOrCreateAsync

        /// <summary>
        /// this is for a project in a solution
        /// </summary>
        private static async Task<ValueTuple<bool, SymbolTreeInfo>> LoadOrCreateAsync(Project project, CancellationToken cancellationToken)
        {
            if (await project.IsForkedProjectWithSemanticChangesAsync(cancellationToken).ConfigureAwait(false))
            {
                return ValueTuple.Create(false, await CreateAsync(project, cancellationToken).ConfigureAwait(false));
            }

            var persistentStorageService = project.Solution.Workspace.Services.GetService<IPersistentStorageService>();
            var version = await project.GetSemanticVersionAsync(cancellationToken).ConfigureAwait(false);

            // attempt to load from persisted state
            SymbolTreeInfo info;
            var succeeded = false;
            using (var storage = persistentStorageService.GetStorage(project.Solution))
            {
                using (var stream = await storage.ReadStreamAsync(project, ProjectSymbolTreeInfoPersistenceName, cancellationToken).ConfigureAwait(false))
                {
                    if (stream != null)
                    {
                        using (var reader = new ObjectReader(stream))
                        {
                            info = ReadFrom(reader);
                            if (info != null && VersionStamp.CanReusePersistedVersion(version, info.version))
                            {
                                return ValueTuple.Create(true, info);
                            }
                        }
                    }
                }

                cancellationToken.ThrowIfCancellationRequested();

                // compute it if we couldn't load it from cache
                info = await CreateAsync(project, cancellationToken).ConfigureAwait(false);
                if (info != null)
                {
                    using (var stream = SerializableBytes.CreateWritableStream())
                    using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
                    {
                        info.WriteTo(writer);
                        stream.Position = 0;

                        succeeded = await storage.WriteStreamAsync(project, ProjectSymbolTreeInfoPersistenceName, stream, cancellationToken).ConfigureAwait(false);
                    }
                }
            }

            return ValueTuple.Create(succeeded, info);
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:52,代码来源:SymbolTreeInfo_Serialization.cs

示例2: UpdateSymbolTreeInfoAsync

            private async Task UpdateSymbolTreeInfoAsync(Project project, CancellationToken cancellationToken)
            {
                if (!project.SupportsCompilation)
                {
                    return;
                }

                // Check the semantic version of this project.  The semantic version will change
                // if any of the source files changed, or if the project version itself changed.
                // (The latter happens when something happens to the project like metadata 
                // changing on disk).
                var version = await project.GetSemanticVersionAsync(cancellationToken).ConfigureAwait(false);

                ProjectInfo projectInfo;
                if (!_projectToInfo.TryGetValue(project.Id, out projectInfo) || projectInfo.VersionStamp != version)
                {
                    var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);

                    // Update the symbol tree infos for metadata and source in parallel.
                    var referencesTask = UpdateReferencesAync(project, compilation, cancellationToken);
                    var projectTask = SymbolTreeInfo.GetInfoForSourceAssemblyAsync(project, cancellationToken);

                    await Task.WhenAll(referencesTask, projectTask).ConfigureAwait(false);

                    // Mark that we're up to date with this project.  Future calls with the same 
                    // semantic version can bail out immediately.
                    projectInfo = new ProjectInfo(version, await projectTask.ConfigureAwait(false));
                    _projectToInfo.AddOrUpdate(project.Id, projectInfo, (_1, _2) => projectInfo);
                }
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:30,代码来源:SymbolTreeInfoIncrementalAnalyzerProvider.cs

示例3: TryGetSourceSymbolTreeInfoAsync

            public async Task<SymbolTreeInfo> TryGetSourceSymbolTreeInfoAsync(
                Project project, CancellationToken cancellationToken)
            {
                ProjectInfo projectInfo;
                if (_projectToInfo.TryGetValue(project.Id, out projectInfo))
                {
                    var version = await project.GetSemanticVersionAsync(cancellationToken).ConfigureAwait(false);
                    if (version == projectInfo.VersionStamp)
                    {
                        return projectInfo.SymbolTreeInfo;
                    }
                }

                return null;
            }
开发者ID:Rickinio,项目名称:roslyn,代码行数:15,代码来源:SymbolTreeInfoIncrementalAnalyzerProvider.cs

示例4: GetInfoForProjectAsync

        /// <summary>
        /// this gives you SymbolTreeInfo for a project
        /// </summary>
        public static async Task<SymbolTreeInfo> GetInfoForProjectAsync(Project project, CancellationToken cancellationToken)
        {
            if (!project.SupportsCompilation)
            {
                return null;
            }

            var branchId = project.Solution.BranchId;
            var workspace = project.Solution.Workspace;

            ConditionalWeakTable<ProjectId, SymbolTreeInfo> infoTable;
            if (!inMemoryCache.TryGetValue(branchId, out infoTable))
            {
                infoTable = inMemoryCache.GetValue(branchId, id => new ConditionalWeakTable<ProjectId, SymbolTreeInfo>());
            }

            // version doesn't need to know about dependent projects since we only care about names of top level declarations.
            var version = await project.GetSemanticVersionAsync(cancellationToken).ConfigureAwait(false);

            // first look to see if we already have the info
            SymbolTreeInfo info;
            if (infoTable.TryGetValue(project.Id, out info) && info != null && info.version == version)
            {
                return info;
            }

            infoTable.Remove(project.Id);

            // next, either get the info from the persistent service or create one
            var persistAndInfo = await LoadOrCreateAsync(project, cancellationToken).ConfigureAwait(false);

            var persisted = persistAndInfo.Item1;
            var newInfo = persistAndInfo.Item2;

            if (!persisted || ShouldCache(project))
            {
                // there could be someone already have put something in here.
                infoTable.GetValue(project.Id, _ => newInfo);
            }

            // use the info we calculated. otherwise, we can encounter a race.
            return newInfo;
        }
开发者ID:nagyist,项目名称:roslyn,代码行数:46,代码来源:SymbolTreeInfo.cs

示例5: CreateAsync

        private static async Task<SymbolTreeInfo> CreateAsync(Project project, CancellationToken cancellationToken)
        {
            var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
            var version = await project.GetSemanticVersionAsync(cancellationToken).ConfigureAwait(false);

            return Create(version, compilation.Assembly, cancellationToken);
        }
开发者ID:EkardNT,项目名称:Roslyn,代码行数:7,代码来源:SymbolTreeInfo_Serialization.cs


注:本文中的Project.GetSemanticVersionAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。