本文整理汇总了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);
}
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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");
}
示例15: GetProjects
private static IEnumerable<Project> GetProjects(Solution solution, IEnumerable<ProjectId> projectIds)
{
return projectIds.Select(id => solution.GetProject(id));
}