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


C# Solution.GetProject方法代码示例

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


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

示例1: GetDocumentsAffectedByRename

        internal static IEnumerable<Document> GetDocumentsAffectedByRename(ISymbol symbol, Solution solution, IEnumerable<RenameLocation> renameLocations)
        {
            if (IsSymbolDefinedInsideMethod(symbol))
            {
                // if the symbol was declared inside of a method, don't check for conflicts in non-renamed documents.
                return renameLocations.Select(l => solution.GetDocument(l.DocumentId));
            }
            else
            {
                var documentsOfRenameSymbolDeclaration = symbol.Locations.Where(l => l.IsInSource).Select(l => solution.GetDocument(l.SourceTree));
                var projectIdsOfRenameSymbolDeclaration =
                    documentsOfRenameSymbolDeclaration.SelectMany(d => d.GetLinkedDocumentIds())
                    .Concat(documentsOfRenameSymbolDeclaration.First().Id)
                    .Select(d => d.ProjectId).Distinct();

                if (ShouldRenameOnlyAffectDeclaringProject(symbol))
                {
                    var isSubset = renameLocations.Select(l => l.DocumentId.ProjectId).Distinct().Except(projectIdsOfRenameSymbolDeclaration).IsEmpty();
                    Contract.ThrowIfFalse(isSubset);
                    return projectIdsOfRenameSymbolDeclaration.SelectMany(p => solution.GetProject(p).Documents);
                }
                else
                {
                    // We are trying to figure out the projects that directly depend on the project that contains the declaration for 
                    // the rename symbol.  Other projects should not be affected by the rename.
                    var relevantProjects = projectIdsOfRenameSymbolDeclaration.Concat(projectIdsOfRenameSymbolDeclaration.SelectMany(p =>
                       solution.GetProjectDependencyGraph().GetProjectsThatDirectlyDependOnThisProject(p))).Distinct();
                    return relevantProjects.SelectMany(p => solution.GetProject(p).Documents);
                }
            }
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:31,代码来源:RenameUtilities.cs

示例2: GetDocumentsAffectedByRename

 internal static IEnumerable<Document> GetDocumentsAffectedByRename(ISymbol symbol, Solution solution, IEnumerable<RenameLocation> renameLocations)
 {
     if (IsSymbolDefinedInsideMethod(symbol))
     {
         // if the symbol was declared inside of a method, don't check for conflicts in non-renamed documents.
         return renameLocations.Select(l => solution.GetDocument(l.DocumentId));
     }
     else
     {
         var documentIdOfRenameSymbolDeclaration = solution.GetDocument(symbol.Locations.First(l => l.IsInSource).SourceTree);
         if (symbol.DeclaredAccessibility == Accessibility.Private)
         {
             // private members or classes cannot be used outside of the project, so we should only scan documents of this project.
             Contract.ThrowIfFalse(renameLocations.Select(l => l.DocumentId.ProjectId).Distinct().Count() == 1);
             return documentIdOfRenameSymbolDeclaration.Project.Documents;
         }
         else
         {
             // We are trying to figure out the projects that directly depend on the project that contains the declaration for 
             // the rename symbol.  Other projects should not be affected by the rename.
             var symbolProjectId = documentIdOfRenameSymbolDeclaration.Project.Id;
             var relevantProjects = SpecializedCollections.SingletonEnumerable(symbolProjectId).Concat(
                 solution.GetProjectDependencyGraph().GetProjectsThatDirectlyDependOnThisProject(symbolProjectId));
             return relevantProjects.SelectMany(p => solution.GetProject(p).Documents);
         }
     }
 }
开发者ID:jerriclynsjohn,项目名称:roslyn,代码行数:27,代码来源:RenameUtilities.cs

示例3: GetSingleChangedProjectChanges

        private static ProjectChanges GetSingleChangedProjectChanges(Solution oldSolution, Solution newSolution)
        {
            var solutionDifferences = newSolution.GetChanges(oldSolution);
            var projectId = solutionDifferences.GetProjectChanges().Single().ProjectId;

            var oldProject = oldSolution.GetProject(projectId);
            var newProject = newSolution.GetProject(projectId);

            return newProject.GetChanges(oldProject);
        }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:SolutionUtilities.cs

示例4: MakeDiagnosticData

 private static DiagnosticData MakeDiagnosticData(ProjectId projectId, Document document, Solution solution, Diagnostic d)
 {
     if (document != null)
     {
         return DiagnosticData.Create(document, d);
     }
     else
     {
         var project = solution.GetProject(projectId);
         Debug.Assert(project != null);
         return DiagnosticData.Create(project, d);
     }
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:13,代码来源:EditAndContinueDiagnosticUpdateSource.cs

示例5: Configure

        /// <summary>
        /// Creates a default readme.md document for the solution
        /// </summary>
        /// <param name="solution">the solution object</param>
        /// <param name="docsFolderName">the solution folder to add the readme to</param>
        public static void Configure(Solution solution, string docsFolderName)
        {
            // create a default readme in the solution root
            var readmePath = Path.Combine(solution.GetDirectory(), ReadmeFileName);
            var readmeTemplate = string.Format(RS.readme, solution.GetName());
            if (!File.Exists(readmePath))
            {
                File.WriteAllText(readmePath, readmeTemplate);
            }

            // add as link to docs folder
            var readmeRelatiePath = readmePath.GetRelativePath(docsFolderName);
            var docsProject = solution.GetProject(docsFolderName);
            docsProject?.AddLinkItem("None", readmeRelatiePath, ReadmeFileName);
        }
开发者ID:matt40k,项目名称:VSAutomate,代码行数:20,代码来源:Readme.cs

示例6: GetDiagnosticsAsync

        public override async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(Solution solution, ProjectId projectId = null, DocumentId documentId = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (documentId != null)
            {
                var diagnostics = await GetProjectDiagnosticsAsync(solution.GetProject(projectId), cancellationToken).ConfigureAwait(false);
                return diagnostics.Where(d => d.DocumentId == documentId).ToImmutableArrayOrEmpty();
            }

            if (projectId != null)
            {
                return await GetProjectDiagnosticsAsync(solution.GetProject(projectId), cancellationToken).ConfigureAwait(false);
            }

            var builder = ImmutableArray.CreateBuilder<DiagnosticData>();
            foreach (var project in solution.Projects)
            {
                builder.AddRange(await GetProjectDiagnosticsAsync(project, cancellationToken).ConfigureAwait(false));
            }

            return builder.ToImmutable();
        }
开发者ID:ehsansajjad465,项目名称:roslyn,代码行数:21,代码来源:DiagnosticIncrementalAnalyzer.cs

示例7: GetDiagnosticsAsync

            public async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(Solution solution, ProjectId projectId, DocumentId documentId, CancellationToken cancellationToken)
            {
                if (solution == null)
                {
                    return GetDiagnosticData();
                }

                if (documentId != null)
                {
                    await AppendDiagnosticsAsync(solution.GetDocument(documentId), cancellationToken).ConfigureAwait(false);
                    return GetDiagnosticData();
                }

                if (projectId != null)
                {
                    await AppendDiagnosticsAsync(solution.GetProject(projectId), cancellationToken: cancellationToken).ConfigureAwait(false);
                    return GetDiagnosticData();
                }

                await AppendDiagnosticsAsync(solution, cancellationToken: cancellationToken).ConfigureAwait(false);
                return GetDiagnosticData();
            }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:22,代码来源:DiagnosticIncrementalAnalyzer_GetDiagnostics.cs

示例8: FindSourceDeclarationsAsyncImpl

        private static async Task<ImmutableArray<ISymbol>> FindSourceDeclarationsAsyncImpl(
            Solution solution, SearchQuery query, SymbolFilter filter, CancellationToken cancellationToken)
        {
            if (query.Name != null && string.IsNullOrWhiteSpace(query.Name))
            {
                return ImmutableArray<ISymbol>.Empty;
            }

            var result = ArrayBuilder<ISymbol>.GetInstance();
            foreach (var projectId in solution.ProjectIds)
            {
                var project = solution.GetProject(projectId);
                var symbols = await FindSourceDeclarationsAsyncImpl(project, query, filter, cancellationToken).ConfigureAwait(false);
                result.AddRange(symbols);
            }

            return result.ToImmutableAndFree();
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:18,代码来源:SymbolFinder_Declarations.cs

示例9: GetDependentProjectsWorkerAsync

        /// <summary>
        /// This method computes the dependent projects that need to be searched for references of the given <paramref name="symbol"/>.
        /// This computation depends on the given symbol's visibility:
        ///     1) Public: Dependent projects include the symbol definition project and all the referencing projects.
        ///     2) Internal: Dependent projects include the symbol definition project and all the referencing projects that have internals access to the definition project.
        ///     3) Private: Dependent projects include the symbol definition project and all the referencing submission projects (which are special and can reference private fields of the previous submission).
        /// 
        /// We perform this computation in two stages:
        ///     1) Compute all the dependent projects (submission + non-submission) and their InternalsVisibleTo semantics to the definition project.
        ///     2) Filter the above computed dependent projects based on symbol visibility.
        /// Dependent projects computed in stage (1) are cached to avoid recomputation.
        /// </summary>
        private static async Task<IEnumerable<Project>> GetDependentProjectsWorkerAsync(
            this ISymbol symbol,
            Solution solution,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // Find the assembly that this symbol comes from.  (Could be a metadata or source
            // assembly).
            symbol = symbol.OriginalDefinition;
            var containingAssembly = symbol.ContainingAssembly;
            if (containingAssembly == null)
            {
                // currently we don't support finding references for a symbol that doesn't have containing assembly symbol
                return SpecializedCollections.EmptyEnumerable<Project>();
            }

            // Find the projects that reference this assembly.

            var sourceProject = solution.GetProject(containingAssembly);
            cancellationToken.ThrowIfCancellationRequested();

            // 1) Compute all the dependent projects (submission + non-submission) and their InternalsVisibleTo semantics to the definition project.
            IEnumerable<DependentProject> dependentProjects;

            var visibility = symbol.GetResultantVisibility();
            if (visibility == SymbolVisibility.Private)
            {
                dependentProjects = await GetDependentProjectsCoreAsync(symbol, solution, sourceProject, visibility, cancellationToken).ConfigureAwait(false);
            }
            else
            {
                // We cache the dependent projects for non-private symbols, check in the cache first.
                ConcurrentDictionary<DefinitionProject, IEnumerable<DependentProject>> dependentProjectsMap = dependentProjectsCache.GetValue(solution, createDependentProjectsMapCallback);
                var key = new DefinitionProject(isSourceProject: sourceProject != null, assemblyName: containingAssembly.Name.ToLower());

                if (!dependentProjectsMap.TryGetValue(key, out dependentProjects))
                {
                    dependentProjects = await GetDependentProjectsCoreAsync(symbol, solution, sourceProject, visibility, cancellationToken).ConfigureAwait(false);
                    dependentProjectsMap.TryAdd(key, dependentProjects);
                }
            }

            // 2) Filter the above computed dependent projects based on symbol visibility.
            return FilterDependentProjectsByVisibility(solution, dependentProjects, visibility);
        }
开发者ID:riversky,项目名称:roslyn,代码行数:58,代码来源:DependentProjectsFinder.cs

示例10: FindSourceDeclarationsAsyncImpl

        private static async Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsyncImpl(
            Solution solution, string name, bool ignoreCase, SymbolFilter filter, CancellationToken cancellationToken)
        {
            var result = new List<ISymbol>();
            foreach (var projectId in solution.ProjectIds)
            {
                var project = solution.GetProject(projectId);
                var symbols = await FindSourceDeclarationsAsyncImpl(project, name, ignoreCase, filter, cancellationToken).ConfigureAwait(false);
                result.AddRange(symbols);
            }

            return result;
        }
开发者ID:reudismam,项目名称:roslyn,代码行数:13,代码来源:SymbolFinder_Declarations.cs

示例11: FindSourceDeclarationsAsync

        /// <summary>
        /// Find the symbols for declarations made in source with a matching name.
        /// </summary>
        public static async Task<IEnumerable<ISymbol>> FindSourceDeclarationsAsync(Solution solution, Func<string, bool> predicate, SymbolFilter filter, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (solution == null)
            {
                throw new ArgumentNullException(nameof(solution));
            }

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

            using (Logger.LogBlock(FunctionId.SymbolFinder_Solution_Predicate_FindSourceDeclarationsAsync, cancellationToken))
            {
                var result = new List<ISymbol>();
                foreach (var projectId in solution.ProjectIds)
                {
                    var project = solution.GetProject(projectId);
                    var symbols = await FindSourceDeclarationsAsync(project, predicate, filter, cancellationToken).ConfigureAwait(false);
                    result.AddRange(symbols);
                }

                return result;
            }
        }
开发者ID:reudismam,项目名称:roslyn,代码行数:28,代码来源:SymbolFinder_Declarations.cs

示例12: GetProjectsThatCouldReferenceTypeAsync

        private static async Task<ISet<ProjectId>> GetProjectsThatCouldReferenceTypeAsync(
            INamedTypeSymbol type, 
            Solution solution, 
            bool searchInMetadata,
            CancellationToken cancellationToken)
        {
            var dependencyGraph = solution.GetProjectDependencyGraph();

            if (searchInMetadata)
            {
                // For a metadata type, find all projects that refer to the metadata assembly that
                // the type is defined in.  Note: we pass 'null' for projects intentionally.  We
                // Need to find all the possible projects that contain this metadata.
                var projectsThatReferenceMetadataAssembly =
                    await DependentProjectsFinder.GetDependentProjectsAsync(
                        type, solution, projects: null, cancellationToken: cancellationToken).ConfigureAwait(false);

                // Now collect all the dependent projects as well.
                var projectsThatCouldReferenceType =
                    projectsThatReferenceMetadataAssembly.SelectMany(
                        p => GetProjectsThatCouldReferenceType(dependencyGraph, p)).ToSet();

                return projectsThatCouldReferenceType;
            }
            else
            {
                // For a source project, find the project that that type was defined in.
                var sourceProject = solution.GetProject(type.ContainingAssembly);
                if (sourceProject == null)
                {
                    return SpecializedCollections.EmptySet<ProjectId>();
                }

                // Now find all the dependent of those projects.
                var projectsThatCouldReferenceType = GetProjectsThatCouldReferenceType(
                    dependencyGraph, sourceProject).ToSet();

                return projectsThatCouldReferenceType;
            }
        }
开发者ID:natidea,项目名称:roslyn,代码行数:40,代码来源:DependentTypeFinder.cs

示例13: CreateSubmissionProject

        private Project CreateSubmissionProject(Solution solution, string languageName, ImmutableArray<string> imports, ImmutableArray<MetadataReference> references)
        {
            var name = "Submission#" + (_submissionCount++);

            // Grab a local copy so we aren't closing over the field that might change. The
            // collection itself is an immutable collection.
            var localCompilationOptions = GetSubmissionCompilationOptions(name, _metadataReferenceResolver, _sourceReferenceResolver, imports);

            var localParseOptions = ParseOptions;

            var projectId = ProjectId.CreateNewId(debugName: name);

            solution = solution.AddProject(
                ProjectInfo.Create(
                    projectId,
                    VersionStamp.Create(),
                    name: name,
                    assemblyName: name,
                    language: languageName,
                    compilationOptions: localCompilationOptions,
                    parseOptions: localParseOptions,
                    documents: null,
                    projectReferences: null,
                    metadataReferences: references,
                    hostObjectType: typeof(InteractiveScriptGlobals),
                    isSubmission: true));

            if (_previousSubmissionProjectId != null)
            {
                solution = solution.AddProjectReference(projectId, new ProjectReference(_previousSubmissionProjectId));
            }

            return solution.GetProject(projectId);
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:34,代码来源:InteractiveEvaluator.cs

示例14: GetProjectOrDocument

            protected static object GetProjectOrDocument(Solution solution, object key)
            {
                var documentId = key as DocumentId;
                if (documentId != null)
                {
                    return solution.GetDocument(documentId);
                }

                var projectId = key as ProjectId;
                if (projectId != null)
                {
                    return solution.GetProject(projectId);
                }

                return Contract.FailWithReturn<object>("Shouldn't reach here");
            }
开发者ID:nileshjagtap,项目名称:roslyn,代码行数:16,代码来源:DiagnosticIncrementalAnalyzer_GetDiagnostics.cs

示例15: GetProjects

 private static IEnumerable<Project> GetProjects(Solution solution, IEnumerable<ProjectId> projectIds)
 {
     return projectIds.Select(id => solution.GetProject(id));
 }
开发者ID:riversky,项目名称:roslyn,代码行数:4,代码来源:DependentProjectsFinder.cs


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