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


C# StateSet.GetState方法代码示例

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


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

示例1: GetDocumentAnalysisDataAsync

            public async Task<AnalysisData> GetDocumentAnalysisDataAsync(DiagnosticAnalyzerDriver analyzerDriver, StateSet stateSet, VersionArgument versions)
            {
                try
                {
                    var document = analyzerDriver.Document;
                    var cancellationToken = analyzerDriver.CancellationToken;

                    var state = stateSet.GetState(StateType.Document);
                    var existingData = await state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);

                    if (CheckSemanticVersions(document, existingData, versions))
                    {
                        return existingData;
                    }

                    var diagnosticData = await GetSemanticDiagnosticsAsync(analyzerDriver, stateSet.Analyzer).ConfigureAwait(false);
                    return new AnalysisData(versions.TextVersion, versions.DataVersion, GetExistingItems(existingData), diagnosticData.AsImmutableOrEmpty());
                }
                catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
开发者ID:noahfalk,项目名称:roslyn,代码行数:23,代码来源:DiagnosticIncrementalAnalyzer.AnalyzerExecutor.cs

示例2: PersistAndReportAsync

        private async Task PersistAndReportAsync(
            StateSet stateSet, StateType stateType, Document document, VersionStamp textVersion, VersionStamp semanticVersion, ImmutableArray<DiagnosticData> diagnostics)
        {
            var state = stateSet.GetState(stateType);
            var existingDiagnostics = await state.TryGetExistingDataAsync(document, CancellationToken.None).ConfigureAwait(false);

            var mergedDiagnostics = MergeDiagnostics(diagnostics, GetExistingDiagnostics(existingDiagnostics));
            await state.PersistAsync(document, new AnalysisData(textVersion, semanticVersion, mergedDiagnostics), CancellationToken.None).ConfigureAwait(false);
            RaiseDiagnosticsUpdated(stateType, document.Id, stateSet, new SolutionArgument(document), mergedDiagnostics);
        }
开发者ID:noahfalk,项目名称:roslyn,代码行数:10,代码来源:DiagnosticIncrementalAnalyzer_BuildSynchronization.cs

示例3: ClearExistingDiagnostics

 private async Task ClearExistingDiagnostics(Project project, StateSet stateSet, CancellationToken cancellationToken)
 {
     var state = stateSet.GetState(StateType.Project);
     var existingData = await state.TryGetExistingDataAsync(project, cancellationToken).ConfigureAwait(false);
     if (existingData?.Items.Length > 0)
     {
         ClearProjectState(project, stateSet);
     }
 }
开发者ID:nevinclement,项目名称:roslyn,代码行数:9,代码来源:DiagnosticIncrementalAnalyzer.cs

示例4: ClearProjectState

        private void ClearProjectState(Project project, StateSet stateSet)
        {
            var state = stateSet.GetState(StateType.Project);

            // remove saved cache
            state.Remove(project.Id);

            // raise diagnostic updated event
            var solutionArgs = new SolutionArgument(project);
            RaiseDiagnosticsUpdated(StateType.Project, project.Id, stateSet, solutionArgs, ImmutableArray<DiagnosticData>.Empty);
        }
开发者ID:nevinclement,项目名称:roslyn,代码行数:11,代码来源:DiagnosticIncrementalAnalyzer.cs

示例5: ClearDocumentState

        private void ClearDocumentState(Document document, StateSet stateSet, StateType type, bool raiseEvent)
        {
            var state = stateSet.GetState(type);

            // remove saved info
            state.Remove(document.Id);

            if (raiseEvent)
            {
                // raise diagnostic updated event
                var documentId = document.Id;
                var solutionArgs = new SolutionArgument(document);

                RaiseDiagnosticsUpdated(type, document.Id, stateSet, solutionArgs, ImmutableArray<DiagnosticData>.Empty);
            }
        }
开发者ID:nevinclement,项目名称:roslyn,代码行数:16,代码来源:DiagnosticIncrementalAnalyzer.cs

示例6: ClearExistingDiagnostics

        private async Task ClearExistingDiagnostics(Project project, StateSet stateSet, CancellationToken cancellationToken)
        {
            var state = stateSet.GetState(StateType.Project);
            var existingData = await state.TryGetExistingDataAsync(project, cancellationToken).ConfigureAwait(false);
            if (existingData?.Items.Length > 0)
            {
                // remove saved cache
                state.Remove(project.Id);

                // raise diagnostic updated event
                RaiseDiagnosticsRemoved(StateType.Project, project.Id, stateSet, new SolutionArgument(project));
            }
        }
开发者ID:vcsjones,项目名称:roslyn,代码行数:13,代码来源:DiagnosticIncrementalAnalyzer.cs

示例7: TryGetDocumentDiagnosticsAsync

            private async Task<bool> TryGetDocumentDiagnosticsAsync(
                StateSet stateSet, StateType stateType, bool supportsSemanticInSpan,
                Func<VersionStamp, VersionStamp, bool> versionCheck,
                Func<DiagnosticAnalyzerDriver, DiagnosticAnalyzer, Task<IEnumerable<DiagnosticData>>> getDiagnostics,
                DiagnosticAnalyzerDriver analyzerDriverOpt = null)
            {
                Func<DiagnosticData, bool> shouldInclude = d =>
                    d.DocumentId == _document.Id &&
                    _range.IntersectsWith(d.TextSpan) &&
                    (_includeSuppressedDiagnostics || !d.IsSuppressed);

                // make sure we get state even when none of our analyzer has ran yet. 
                // but this shouldn't create analyzer that doesn't belong to this project (language)
                var state = stateSet.GetState(stateType);

                // see whether we can use existing info
                var existingData = await state.TryGetExistingDataAsync(_document, _cancellationToken).ConfigureAwait(false);
                if (existingData != null && versionCheck(existingData.TextVersion, existingData.DataVersion))
                {
                    if (existingData.Items == null || existingData.Items.Length == 0)
                    {
                        return true;
                    }

                    Diagnostics.AddRange(existingData.Items.Where(shouldInclude));
                    return true;
                }

                // check whether we want up-to-date document wide diagnostics
                if (!BlockForData(stateType, supportsSemanticInSpan))
                {
                    return false;
                }

                var dx = await getDiagnostics(analyzerDriverOpt, stateSet.Analyzer).ConfigureAwait(false);
                if (dx != null)
                {
                    // no state yet
                    Diagnostics.AddRange(dx.Where(shouldInclude));
                }

                return true;
            }
开发者ID:nemec,项目名称:roslyn,代码行数:43,代码来源:DiagnosticIncrementalAnalyzer_GetLatestDiagnosticsForSpan.cs

示例8: GetDocumentBodyAnalysisDataAsync

            public async Task<AnalysisData> GetDocumentBodyAnalysisDataAsync(
                StateSet stateSet, VersionArgument versions, DiagnosticAnalyzerDriver analyzerDriver,
                SyntaxNode root, SyntaxNode member, int memberId, bool supportsSemanticInSpan, MemberRangeMap.MemberRanges ranges)
            {
                try
                {
                    var document = analyzerDriver.Document;
                    var cancellationToken = analyzerDriver.CancellationToken;

                    var state = stateSet.GetState(StateType.Document);
                    var existingData = await state.TryGetExistingDataAsync(document, cancellationToken).ConfigureAwait(false);

                    ImmutableArray<DiagnosticData> diagnosticData;
                    if (supportsSemanticInSpan && CanUseRange(memberId, ranges.Ranges) && CanUseDocumentState(existingData, ranges.TextVersion, versions.DataVersion))
                    {
                        var memberDxData = await GetSemanticDiagnosticsAsync(analyzerDriver, stateSet.Analyzer).ConfigureAwait(false);

                        diagnosticData = _owner.UpdateDocumentDiagnostics(existingData, ranges.Ranges, memberDxData.AsImmutableOrEmpty(), root.SyntaxTree, member, memberId);
                        ValidateMemberDiagnostics(stateSet.Analyzer, document, root, diagnosticData);
                    }
                    else
                    {
                        // if we can't re-use existing document state, only option we have is updating whole document state here.
                        var dx = await GetSemanticDiagnosticsAsync(analyzerDriver, stateSet.Analyzer).ConfigureAwait(false);
                        diagnosticData = dx.AsImmutableOrEmpty();
                    }
                    return new AnalysisData(versions.TextVersion, versions.DataVersion, GetExistingItems(existingData), diagnosticData);
                }
                catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
                {
                    throw ExceptionUtilities.Unreachable;
                }
            }
开发者ID:noahfalk,项目名称:roslyn,代码行数:33,代码来源:DiagnosticIncrementalAnalyzer.AnalyzerExecutor.cs


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