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


C# Project.GetDocument方法代码示例

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


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

示例1: ToDiagnosticData

        public static DiagnosticData ToDiagnosticData(this Diagnostic diagnostic, Project project)
        {
            if (diagnostic.Location.IsInSource)
            {
                return DiagnosticData.Create(project.GetDocument(diagnostic.Location.SourceTree), diagnostic);
            }

            return DiagnosticData.Create(project, diagnostic);
        }
开发者ID:robertoenbarcelona,项目名称:roslyn,代码行数:9,代码来源:Extensions.cs

示例2: ToDiagnosticData

        public static DiagnosticData ToDiagnosticData(this Diagnostic diagnostic, Project project)
        {
            if (diagnostic.Location.IsInSource)
            {
                return DiagnosticData.Create(project.GetDocument(diagnostic.Location.SourceTree), diagnostic);
            }

            if (diagnostic.Location.Kind == LocationKind.ExternalFile)
            {
                var document = project.Documents.FirstOrDefault(d => d.FilePath == diagnostic.Location.GetLineSpan().Path);
                if (document != null)
                {
                    return DiagnosticData.Create(document, diagnostic);
                }
            }

            return DiagnosticData.Create(project, diagnostic);
        }
开发者ID:AnthonyDGreen,项目名称:roslyn,代码行数:18,代码来源:Extensions.cs

示例3: RaiseProjectDiagnosticsCreated

        private void RaiseProjectDiagnosticsCreated(Project project, StateSet stateSet, DiagnosticAnalysisResult oldAnalysisResult, DiagnosticAnalysisResult newAnalysisResult, Action<DiagnosticsUpdatedArgs> raiseEvents)
        {
            foreach (var documentId in newAnalysisResult.DocumentIds)
            {
                var document = project.GetDocument(documentId);
                if (document == null)
                {
                    // it can happen with build synchronization since, in build case, 
                    // we don't have actual snapshot (we have no idea what sources out of proc build has picked up)
                    // so we might be out of sync.
                    // example of such cases will be changing anything about solution while building is going on.
                    // it can be user explict actions such as unloading project, deleting a file, but also it can be 
                    // something project system or roslyn workspace does such as populating workspace right after
                    // solution is loaded.
                    continue;
                }

                RaiseDocumentDiagnosticsIfNeeded(document, stateSet, AnalysisKind.NonLocal, oldAnalysisResult, newAnalysisResult, raiseEvents);

                // we don't raise events for active file. it will be taken cared by active file analysis
                if (stateSet.IsActiveFile(documentId))
                {
                    continue;
                }

                RaiseDocumentDiagnosticsIfNeeded(document, stateSet, AnalysisKind.Syntax, oldAnalysisResult, newAnalysisResult, raiseEvents);
                RaiseDocumentDiagnosticsIfNeeded(document, stateSet, AnalysisKind.Semantic, oldAnalysisResult, newAnalysisResult, raiseEvents);
            }

            RaiseDiagnosticsCreated(project, stateSet, newAnalysisResult.Others, raiseEvents);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:31,代码来源:DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs

示例4: GetDiagnosticData

        private static IEnumerable<DiagnosticData> GetDiagnosticData(Project project, IEnumerable<Diagnostic> diagnostics)
        {
            if (diagnostics == null)
            {
                yield break;
            }

            foreach (var diagnostic in diagnostics)
            {
                if (diagnostic.Location == null || diagnostic.Location == Location.None)
                {
                    yield return DiagnosticData.Create(project, diagnostic);
                    continue;
                }

                var document = project.GetDocument(diagnostic.Location.SourceTree);
                if (document == null)
                {
                    continue;
                }

                yield return DiagnosticData.Create(document, diagnostic);
            }
        }
开发者ID:nevinclement,项目名称:roslyn,代码行数:24,代码来源:DiagnosticIncrementalAnalyzer.cs

示例5: RaiseProjectDiagnosticsUpdated

        private void RaiseProjectDiagnosticsUpdated(Project project, StateSet stateSet, ImmutableArray<DiagnosticData> diagnostics)
        {
            var group = diagnostics.GroupBy(d => d.DocumentId);
            foreach (var kv in group)
            {
                if (kv.Key == null)
                {
                    RaiseDiagnosticsUpdated(StateType.Project, project.Id, stateSet, new SolutionArgument(project), kv.ToImmutableArrayOrEmpty());
                    continue;
                }

                RaiseDiagnosticsUpdated(StateType.Project, kv.Key, stateSet, new SolutionArgument(project.GetDocument(kv.Key)), kv.ToImmutableArrayOrEmpty());
            }
        }
开发者ID:nevinclement,项目名称:roslyn,代码行数:14,代码来源:DiagnosticIncrementalAnalyzer.cs

示例6: RaiseProjectDiagnosticsRemovedIfNeeded

        private void RaiseProjectDiagnosticsRemovedIfNeeded(
            Project project, StateSet stateSet, ImmutableArray<DiagnosticData> existingItems, ImmutableArray<DiagnosticData> newItems)
        {
            if (existingItems.Length == 0)
            {
                return;
            }

            var removedItems = existingItems.GroupBy(d => d.DocumentId).Select(g => g.Key).Except(newItems.GroupBy(d => d.DocumentId).Select(g => g.Key));
            foreach (var documentId in removedItems)
            {
                if (documentId == null)
                {
                    RaiseDiagnosticsUpdated(StateType.Project, project.Id, stateSet, new SolutionArgument(project), ImmutableArray<DiagnosticData>.Empty);
                    continue;
                }

                var document = project.GetDocument(documentId);
                var argument = documentId == null ? new SolutionArgument(null, documentId.ProjectId, documentId) : new SolutionArgument(document);
                RaiseDiagnosticsUpdated(StateType.Project, documentId, stateSet, argument, ImmutableArray<DiagnosticData>.Empty);
            }
        }
开发者ID:nevinclement,项目名称:roslyn,代码行数:22,代码来源:DiagnosticIncrementalAnalyzer.cs

示例7: PersistProjectData

        private static async Task PersistProjectData(Project project, DiagnosticState state, AnalysisData data)
        {
            // TODO: Cancellation is not allowed here to prevent data inconsistency. But there is still a possibility of data inconsistency due to
            //       things like exception. For now, I am letting it go and let v2 engine take care of it properly. If v2 doesnt come online soon enough
            //       more refactoring is required on project state.

            // clear all existing data
            state.Remove(project.Id);
            foreach (var document in project.Documents)
            {
                state.Remove(document.Id);
            }

            // quick bail out
            if (data.Items.Length == 0)
            {
                return;
            }

            // save new data
            var group = data.Items.GroupBy(d => d.DocumentId);
            foreach (var kv in group)
            {
                if (kv.Key == null)
                {
                    // save project scope diagnostics
                    await state.PersistAsync(project, new AnalysisData(data.TextVersion, data.DataVersion, kv.ToImmutableArrayOrEmpty()), CancellationToken.None).ConfigureAwait(false);
                    continue;
                }

                // save document scope diagnostics
                var document = project.GetDocument(kv.Key);
                if (document == null)
                {
                    continue;
                }

                await state.PersistAsync(document, new AnalysisData(data.TextVersion, data.DataVersion, kv.ToImmutableArrayOrEmpty()), CancellationToken.None).ConfigureAwait(false);
            }
        }
开发者ID:nevinclement,项目名称:roslyn,代码行数:40,代码来源:DiagnosticIncrementalAnalyzer.cs

示例8: EnqueueWorkItemAsync

 private async Task EnqueueWorkItemAsync(Project project, InvocationReasons invocationReasons)
 {
     foreach (var documentId in project.DocumentIds)
     {
         var document = project.GetDocument(documentId);
         await EnqueueWorkItemAsync(document, invocationReasons).ConfigureAwait(false);
     }
 }
开发者ID:GloryChou,项目名称:roslyn,代码行数:8,代码来源:WorkCoordinator.cs

示例9: RaiseProjectDiagnosticsCreated

        private void RaiseProjectDiagnosticsCreated(Project project, StateSet stateSet, AnalysisResult oldAnalysisResult, AnalysisResult newAnalysisResult, Action<DiagnosticsUpdatedArgs> raiseEvents)
        {
            foreach (var documentId in newAnalysisResult.DocumentIds)
            {
                var document = project.GetDocument(documentId);
                Contract.ThrowIfNull(document);

                RaiseDocumentDiagnosticsIfNeeded(document, stateSet, AnalysisKind.NonLocal, oldAnalysisResult, newAnalysisResult, raiseEvents);

                // we don't raise events for active file. it will be taken cared by active file analysis
                if (stateSet.IsActiveFile(documentId))
                {
                    continue;
                }

                RaiseDocumentDiagnosticsIfNeeded(document, stateSet, AnalysisKind.Syntax, oldAnalysisResult, newAnalysisResult, raiseEvents);
                RaiseDocumentDiagnosticsIfNeeded(document, stateSet, AnalysisKind.Semantic, oldAnalysisResult, newAnalysisResult, raiseEvents);
            }

            RaiseDiagnosticsCreated(project, stateSet, newAnalysisResult.Others, raiseEvents);
        }
开发者ID:rgani,项目名称:roslyn,代码行数:21,代码来源:DiagnosticIncrementalAnalyzer_IncrementalAnalyzer.cs

示例10: GetChangedDocumentsAnalyses

        private List<ValueTuple<DocumentId, AsyncLazy<DocumentAnalysisResults>>> GetChangedDocumentsAnalyses(Project baseProject, Project project)
        {
            var changes = project.GetChanges(baseProject);
            var changedDocuments = changes.GetChangedDocuments().Concat(changes.GetAddedDocuments());
            var result = new List<ValueTuple<DocumentId, AsyncLazy<DocumentAnalysisResults>>>();

            lock (_analysesGuard)
            {
                foreach (var changedDocumentId in changedDocuments)
                {
                    result.Add(ValueTuple.Create(changedDocumentId, GetDocumentAnalysisNoLock(project.GetDocument(changedDocumentId))));
                }
            }

            return result;
        }
开发者ID:daking2014,项目名称:roslyn,代码行数:16,代码来源:EditSession.cs

示例11: ConvertLocationAsync

        public static async Task<Location> ConvertLocationAsync(
            this DiagnosticDataLocation dataLocation, Project project, CancellationToken cancellationToken)
        {
            if (dataLocation?.DocumentId == null)
            {
                return Location.None;
            }

            var document = project.GetDocument(dataLocation?.DocumentId);
            if (document == null)
            {
                return Location.None;
            }


            if (document.SupportsSyntaxTree)
            {
                var syntacticDocument = await SyntacticDocument.CreateAsync(document, cancellationToken).ConfigureAwait(false);
                return dataLocation.ConvertLocation(syntacticDocument);
            }

            return dataLocation.ConvertLocation();
        }
开发者ID:AnthonyDGreen,项目名称:roslyn,代码行数:23,代码来源:Extensions.cs

示例12: EnqueueWorkItem

 private void EnqueueWorkItem(Project project, InvocationReasons invocationReasons)
 {
     foreach (var documentId in project.DocumentIds)
     {
         var document = project.GetDocument(documentId);
         EnqueueWorkItem(document, invocationReasons);
     }
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:8,代码来源:WorkCoordinator.cs

示例13: Deserialize

        private static ImmutableDictionary<DocumentId, ImmutableArray<DiagnosticData>> Deserialize(
            ObjectReader reader,
            DiagnosticDataSerializer serializer,
            Project project,
            CancellationToken cancellationToken)
        {
            var count = reader.ReadInt32();
            var map = ImmutableDictionary.CreateBuilder<DocumentId, ImmutableArray<DiagnosticData>>();
            for (var i = 0; i < count; i++)
            {
                var documentId = Serializer.DeserializeDocumentId(reader, cancellationToken);
                var diagnostics = serializer.ReadFrom(reader, project.GetDocument(documentId), cancellationToken);

                map.Add(documentId, diagnostics);
            }

            return map.ToImmutable();
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:18,代码来源:DiagnosticResultSerializer.cs

示例14: Create

        public static DiagnosticData Create(Project project, Diagnostic diagnostic)
        {
            if (diagnostic.Location.IsInSource)
            {
                // Project diagnostic reported at a document location (e.g. compilation end action diagnostics).
                var document = project.GetDocument(diagnostic.Location.SourceTree);
                if (document != null)
                {
                    return Create(document, diagnostic);
                }
            }

            return new DiagnosticData(
                diagnostic.Id,
                diagnostic.Descriptor.Category,
                diagnostic.GetMessage(CultureInfo.CurrentUICulture),
                diagnostic.Descriptor.MessageFormat.ToString(USCultureInfo),
                diagnostic.Severity,
                diagnostic.DefaultSeverity,
                diagnostic.Descriptor.IsEnabledByDefault,
                diagnostic.WarningLevel,
                diagnostic.Descriptor.CustomTags.AsImmutableOrEmpty(),
                project.Solution.Workspace,
                project.Id,
                title: diagnostic.Descriptor.Title.ToString(CultureInfo.CurrentUICulture),
                description: diagnostic.Descriptor.Description.ToString(CultureInfo.CurrentUICulture),
                helpLink: diagnostic.Descriptor.HelpLinkUri);
        }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:28,代码来源:DiagnosticData.cs

示例15: ConvertLocationAsync

        private static async Task<Location> ConvertLocationAsync(
            Project project, DiagnosticDataLocation dataLocation, ImmutableDictionary<DocumentId, SyntaxTree> documentIdToTree, CancellationToken cancellationToken)
        {
            if (dataLocation?.DocumentId != null)
            {
                var document = project.GetDocument(dataLocation?.DocumentId);
                if (document != null)
                {
                    if (document.SupportsSyntaxTree)
                    {
                        var syntaxTree = documentIdToTree != null
                            ? documentIdToTree[document.Id]
                            : await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
                        var span = dataLocation.SourceSpan ?? GetTextSpan(dataLocation, syntaxTree.GetText());
                        return syntaxTree.GetLocation(span);
                    }
                    else if (dataLocation?.OriginalFilePath != null && dataLocation.SourceSpan != null)
                    {
                        var span = dataLocation.SourceSpan.Value;
                        return Location.Create(dataLocation?.OriginalFilePath, span, new LinePositionSpan(
                            new LinePosition(dataLocation.OriginalStartLine, dataLocation.OriginalStartColumn),
                            new LinePosition(dataLocation.OriginalEndLine, dataLocation.OriginalEndColumn)));
                    }
                }
            }

            return Location.None;
        }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:28,代码来源:DiagnosticData.cs


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