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


C# Project.GetCompilationAsync方法代码示例

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


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

示例1: AnalysisContext

 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="project">Project</param>
 private AnalysisContext(Project project)
 {
     this.Solution = project.Solution;
     this.Compilation = project.GetCompilationAsync().Result;
     this.RegisteredImmutableTypes = new HashSet<Type>();
     this.GivesUpOwnershipMethods = new Dictionary<string, ISet<int>>();
 }
开发者ID:yonglehou,项目名称:PSharp,代码行数:11,代码来源:AnalysisContext.cs

示例2: ProcessProjectAsync

        private async Task ProcessProjectAsync(
            Project project,
            DocumentMap documentMap)
        {
            using (Logger.LogBlock(FunctionId.FindReference_ProcessProjectAsync, project.Name, _cancellationToken))
            {
                // make sure we hold onto compilation while we search documents belong to this project
                var compilation = await project.GetCompilationAsync(_cancellationToken).ConfigureAwait(false);

                var documentTasks = new List<Task>();
                foreach (var kvp in documentMap)
                {
                    var document = kvp.Key;

                    if (document.Project == project)
                    {
                        var documentQueue = kvp.Value;

                        documentTasks.Add(Task.Run(() => ProcessDocumentQueueAsync(
                            document, documentQueue), _cancellationToken));
                    }
                }

                await Task.WhenAll(documentTasks).ConfigureAwait(false);

                GC.KeepAlive(compilation);
            }
        }
开发者ID:TyOverby,项目名称:roslyn,代码行数:28,代码来源:FindReferencesSearchEngine_ProjectProcessing.cs

示例3: FindDeclarationsAsyncImpl

        private static async Task<IEnumerable<ISymbol>> FindDeclarationsAsyncImpl(
            Project project, string name, bool ignoreCase, SymbolFilter criteria, CancellationToken cancellationToken)
        {
            var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);

            var list = new List<ISymbol>();

            // get declarations from the compilation's assembly
            await AddDeclarationsAsync(project, name, ignoreCase, criteria, list, cancellationToken).ConfigureAwait(false);

            // get declarations from directly referenced projects and metadata
            foreach (var assembly in compilation.GetReferencedAssemblySymbols())
            {
                var assemblyProject = project.Solution.GetProject(assembly, cancellationToken);
                if (assemblyProject != null)
                {
                    await AddDeclarationsAsync(assemblyProject, compilation, assembly, name, ignoreCase, criteria, list, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    await AddDeclarationsAsync(project.Solution, assembly, GetMetadataReferenceFilePath(compilation.GetMetadataReference(assembly)), name, ignoreCase, criteria, list, cancellationToken).ConfigureAwait(false);
                }
            }

            return TranslateNamespaces(list, compilation);
        }
开发者ID:reudismam,项目名称:roslyn,代码行数:26,代码来源:SymbolFinder_Declarations.cs

示例4: GetPeekableItemsAsync

        public async Task<IEnumerable<IPeekableItem>> GetPeekableItemsAsync(ISymbol symbol, Project project, IPeekResultFactory peekResultFactory, CancellationToken cancellationToken)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException(nameof(symbol));
            }

            if (project == null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            if (peekResultFactory == null)
            {
                throw new ArgumentNullException(nameof(peekResultFactory));
            }

            var results = new List<IPeekableItem>();

            var solution = project.Solution;
            var sourceDefinition = await SymbolFinder.FindSourceDefinitionAsync(symbol, solution, cancellationToken).ConfigureAwait(false);

            // And if our definition actually is from source, then let's re-figure out what project it came from
            if (sourceDefinition != null)
            {
                var originatingProject = solution.GetProject(sourceDefinition.ContainingAssembly, cancellationToken);

                project = originatingProject ?? project;
            }

            string filePath;
            int lineNumber;
            int charOffset;

            var symbolNavigationService = solution.Workspace.Services.GetService<ISymbolNavigationService>();

            if (symbolNavigationService.WouldNavigateToSymbol(symbol, solution, out filePath, out lineNumber, out charOffset))
            {
                var position = new LinePosition(lineNumber, charOffset);
                results.Add(new ExternalFilePeekableItem(new FileLinePositionSpan(filePath, position, position), PredefinedPeekRelationships.Definitions, peekResultFactory));
            }
            else
            {
                var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
                var symbolKey = SymbolKey.Create(symbol, compilation, cancellationToken);

                var firstLocation = symbol.Locations.FirstOrDefault();
                if (firstLocation != null)
                {
                    if (firstLocation.IsInSource || _metadataAsSourceFileService.IsNavigableMetadataSymbol(symbol))
                    {
                        results.Add(new DefinitionPeekableItem(solution.Workspace, project.Id, symbolKey, peekResultFactory, _metadataAsSourceFileService));
                    }
                }
            }

            return results;
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:58,代码来源:PeekableItemFactory.cs

示例5: GetInfoForSourceAssemblyAsync

        public static async Task<SymbolTreeInfo> GetInfoForSourceAssemblyAsync(
            Project project, CancellationToken cancellationToken)
        {
            var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);

            return await LoadOrCreateSourceSymbolTreeInfoAsync(
                project.Solution, compilation.Assembly, project.FilePath,
                loadOnly: false, cancellationToken: cancellationToken).ConfigureAwait(false);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:9,代码来源:SymbolTreeInfo_Source.cs

示例6: CreateAnalyzerDriverAsync

            public async Task<CompilationWithAnalyzers> CreateAnalyzerDriverAsync(
                Project project, IEnumerable<DiagnosticAnalyzer> analyzers, bool includeSuppressedDiagnostics, CancellationToken cancellationToken)
            {
                if (!project.SupportsCompilation)
                {
                    return null;
                }

                var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);

                // Create driver that holds onto compilation and associated analyzers
                return CreateAnalyzerDriver(
                    project, compilation, analyzers, logAnalyzerExecutionTime: false, reportSuppressedDiagnostics: includeSuppressedDiagnostics);
            }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:14,代码来源:DiagnosticIncrementalAnalyzer.CompilationManager.cs

示例7: GenerateSourceAsync

            public async Task<MetadataAsSourceFile> GenerateSourceAsync(string symbolMetadataName = null, Project project = null)
            {
                symbolMetadataName = symbolMetadataName ?? AbstractMetadataAsSourceTests.DefaultSymbolMetadataName;
                project = project ?? this.DefaultProject;

                // Get an ISymbol corresponding to the metadata name
                var compilation = await project.GetCompilationAsync();
                var diagnostics = compilation.GetDiagnostics().ToArray();
                Assert.Equal(0, diagnostics.Length);
                var symbol = await ResolveSymbolAsync(symbolMetadataName, compilation);

                // Generate and hold onto the result so it can be disposed of with this context
                var result = await _metadataAsSourceService.GetGeneratedFileAsync(project, symbol);

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

示例8: AnalyzeProjectAsync

            public override async Task AnalyzeProjectAsync(Project project, bool semanticsChanged, CancellationToken cancellationToken)
            {
                if (_symbolCountByProjectMap == null || !project.SupportsCompilation || !semanticsChanged)
                {
                    return;
                }

                // we do this just to report total symbol numbers
                var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);

                var info = SymbolTreeInfo.Create(VersionStamp.Default, compilation.Assembly, cancellationToken);
                if (info != null)
                {
                    RecordCount(project.Id, info.Count);
                }
            }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:16,代码来源:SymbolTreeInfoIncrementalAnalyzerProvider.cs

示例9: FindDeclarationsAsyncImpl

        private static async Task<IEnumerable<ISymbol>> FindDeclarationsAsyncImpl(Project project, string name, bool ignoreCase, CancellationToken cancellationToken)
        {
            var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);

            var list = new List<ISymbol>();

            // get declarations from the compilation's assembly
            await AddDeclarationsAsync(project, compilation.Assembly, name, ignoreCase, list, cancellationToken).ConfigureAwait(false);

            // get declarations from directly referenced projects and metadata
            foreach (var mr in compilation.References)
            {
                var assembly = compilation.GetAssemblyOrModuleSymbol(mr) as IAssemblySymbol;
                if (assembly != null)
                {
                    var assemblyProject = project.Solution.GetProject(assembly, cancellationToken);
                    if (assemblyProject != null)
                    {
                        await AddDeclarationsAsync(assemblyProject, assembly, name, ignoreCase, list, cancellationToken).ConfigureAwait(false);
                    }
                    else
                    {
                        await AddDeclarationsAsync(project.Solution, assembly, GetMetadataReferenceFilePath(mr), name, ignoreCase, list, cancellationToken).ConfigureAwait(false);
                    }
                }
            }

            // get declarations from metadata referenced in source directives
            foreach (var mr in compilation.DirectiveReferences)
            {
                var assembly = compilation.GetAssemblyOrModuleSymbol(mr) as IAssemblySymbol;
                if (assembly != null)
                {
                    await AddDeclarationsAsync(project.Solution, assembly, GetMetadataReferenceFilePath(mr), name, ignoreCase, list, cancellationToken).ConfigureAwait(false);
                }
            }

            return TranslateNamespaces(list, compilation);
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:39,代码来源:SymbolFinder_Declarations.cs

示例10: CreateAsync

 public static async Task<RemoveSuppressionCodeAction> CreateAsync(
     SuppressionTargetInfo suppressionTargetInfo,
     Document documentOpt,
     Project project,
     Diagnostic diagnostic,
     AbstractSuppressionCodeFixProvider fixer,
     CancellationToken cancellationToken)
 {
     var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
     var attribute = diagnostic.GetSuppressionInfo(compilation).Attribute;
     if (attribute != null)
     {
         return AttributeRemoveAction.Create(attribute, project, diagnostic, fixer);
     }
     else if (documentOpt != null && !SuppressionHelpers.IsSynthesizedExternalSourceDiagnostic(diagnostic))
     {
         return PragmaRemoveAction.Create(suppressionTargetInfo, documentOpt, diagnostic, fixer);
     }
     else
     {
         return null;
     }
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:23,代码来源:AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction.cs

示例11: ProcessProjectAsync

        private async Task ProcessProjectAsync(
            Project project,
            Dictionary<Document, List<ValueTuple<ISymbol, IReferenceFinder>>> map,
            ProgressWrapper wrapper)
        {
            using (Logger.LogBlock(FunctionId.FindReference_ProcessProjectAsync, project.Name, this.cancellationToken))
            {
                // make sure we hold onto compilation while we search documents belong to this project
                var compilation = await project.GetCompilationAsync(this.cancellationToken).ConfigureAwait(false);

                var documentTasks = new List<Task>();
                foreach (var kvp in map)
                {
                    var document = kvp.Key;
                    var documentQueue = kvp.Value;

                    documentTasks.Add(Task.Run(() => ProcessDocumentQueueAsync(document, documentQueue, wrapper), this.cancellationToken));
                }

                await Task.WhenAll(documentTasks).ConfigureAwait(false);

                GC.KeepAlive(compilation);
            }
        }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:24,代码来源:FindReferencesSearchEngine_ProjectProcessing.cs

示例12: EmitProjectDeltaAsync

        public async Task<Deltas> EmitProjectDeltaAsync(Project project, EmitBaseline baseline, CancellationToken cancellationToken)
        {
            try
            {
                Debug.Assert(!_stoppedAtException);

                var changes = await GetProjectChangesAsync(project, cancellationToken).ConfigureAwait(false);
                var currentCompilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
                var allAddedSymbols = await GetAllAddedSymbols(cancellationToken).ConfigureAwait(false);

                var pdbStream = new MemoryStream();
                var updatedMethods = new List<MethodDefinitionHandle>();

                using (var metadataStream = SerializableBytes.CreateWritableStream())
                using (var ilStream = SerializableBytes.CreateWritableStream())
                {
                    EmitDifferenceResult result = currentCompilation.EmitDifference(
                        baseline,
                        changes.SemanticEdits,
                        s => allAddedSymbols?.Contains(s) ?? false,
                        metadataStream,
                        ilStream,
                        pdbStream,
                        updatedMethods,
                        cancellationToken);

                    int[] updateMethodTokens = updatedMethods.Select(h => MetadataTokens.GetToken(h)).ToArray();
                    return new Deltas(ilStream.ToArray(), metadataStream.ToArray(), updateMethodTokens, pdbStream, changes.LineChanges, result);
                }
            }
            catch (Exception e) when (FatalError.ReportUnlessCanceled(e))
            {
                throw ExceptionUtilities.Unreachable;
            }
        }
开发者ID:daking2014,项目名称:roslyn,代码行数:35,代码来源:EditSession.cs

示例13: GetUnfilteredSymbolsAsync

 private static async Task<ImmutableArray<ISymbol>> GetUnfilteredSymbolsAsync(
     Project project,
     SearchQuery query,
     SymbolFilter filter,
     Compilation startingCompilation,
     IAssemblySymbol startingAssembly,
     CancellationToken cancellationToken)
 {
     var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
     if (startingCompilation != null && startingAssembly != null && compilation.Assembly != startingAssembly)
     {
         // Return symbols from skeleton assembly in this case so that symbols have the same language as startingCompilation.
         return compilation.GetSymbolsWithName(query.GetPredicate(), filter, cancellationToken)
             .Select(s => s.GetSymbolKey().Resolve(startingCompilation, cancellationToken: cancellationToken).Symbol)
             .WhereNotNull()
             .ToImmutableArray();
     }
     else
     {
         return compilation.GetSymbolsWithName(query.GetPredicate(), filter, cancellationToken)
                           .ToImmutableArray();
     }
 }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:23,代码来源:SymbolFinder_Declarations.cs

示例14: GetSuppressionsAsync

        public async Task<IEnumerable<CodeFix>> GetSuppressionsAsync(Project project, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
        {
            if (!project.SupportsCompilation)
            {
                return SpecializedCollections.EmptyEnumerable<CodeFix>();
            }

            var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
            var suppressionTargetInfo = new SuppressionTargetInfo() { TargetSymbol = compilation.Assembly };
            return await GetSuppressionsAsync(documentOpt: null, project: project, diagnostics: diagnostics,
                suppressionTargetInfo: suppressionTargetInfo, skipSuppressMessage: false, skipUnsuppress: false, cancellationToken: cancellationToken).ConfigureAwait(false);
        }
开发者ID:hbarve1,项目名称:roslyn,代码行数:12,代码来源:AbstractSuppressionCodeFixProvider.cs

示例15: CreateAsync

                public static async Task<CompilationSet> CreateAsync(Project project, CompilationSet oldCompilationSet, CancellationToken cancellationToken)
                {
                    var compilation = await project.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
                    var version = await project.GetDependentSemanticVersionAsync(cancellationToken).ConfigureAwait(false);
                    var map = GetTreeMap(project, compilation, oldCompilationSet, cancellationToken);

                    ValidateTreeMap(map, project, compilation);
                    return new CompilationSet(version, GetCompilation(project, compilation), map);
                }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:9,代码来源:SemanticModelWorkspaceServiceFactory.cs


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