Skip to content

Commit

Permalink
Merge pull request #74747 from CyrusNajmabadi/foreachNonVar
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi authored Aug 13, 2024
2 parents 9e91ca6 + f414bd2 commit 497f9d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,11 @@ public static ProjectUpdateState AddProjectOutputPath_NoLock(
}

/// <summary>
/// Attempts to convert all metadata references to <paramref name="outputPath"/> to a project reference to <paramref name="projectIdToReference"/>.
/// Attempts to convert all metadata references to <paramref name="outputPath"/> to a project reference to <paramref
/// name="projectIdToReference"/>.
/// </summary>
/// <param name="projectIdToReference">The <see cref="ProjectId"/> of the project that could be referenced in place of the output path.</param>
/// <param name="projectIdToReference">The <see cref="ProjectId"/> of the project that could be referenced in place
/// of the output path.</param>
/// <param name="outputPath">The output path to replace.</param>
[PerformanceSensitive("https://github.com/dotnet/roslyn/issues/31306",
Constraint = "Avoid calling " + nameof(CodeAnalysis.Solution.GetProject) + " to avoid realizing all projects.")]
Expand All @@ -522,9 +524,10 @@ private static ProjectUpdateState ConvertMetadataReferencesToProjectReferences_N
{
if (CanConvertMetadataReferenceToProjectReference(solutionChanges.Solution, projectIdToRetarget, referencedProjectId: projectIdToReference))
{
// PERF: call GetProjectState instead of GetProject, otherwise creating a new project might force all
// Project instances to get created.
foreach (PortableExecutableReference reference in solutionChanges.Solution.GetProjectState(projectIdToRetarget)!.MetadataReferences)
// PERF: call GetRequiredProjectState instead of GetRequiredProject, otherwise creating a new project
// might force all Project instances to get created.
var projectState = solutionChanges.Solution.GetRequiredProjectState(projectIdToRetarget);
foreach (var reference in projectState.MetadataReferences.OfType<PortableExecutableReference>())
{
if (string.Equals(reference.FilePath, outputPath, StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -540,8 +543,8 @@ private static ProjectUpdateState ConvertMetadataReferencesToProjectReferences_N
projectUpdateState = projectUpdateState.WithProjectReferenceInfo(projectIdToRetarget,
projectInfo.WithConvertedProjectReference(reference.FilePath!, projectReference));

// We have converted one, but you could have more than one reference with different aliases
// that we need to convert, so we'll keep going
// We have converted one, but you could have more than one reference with different aliases that
// we need to convert, so we'll keep going
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ private DocumentInfo CreateDocumentInfo(DocumentId documentId, string name, Sour
filePath: filePath);
}

private ProjectState GetRequiredProjectState(ProjectId projectId)
internal ProjectState GetRequiredProjectState(ProjectId projectId)
=> this.SolutionState.GetProjectState(projectId) ?? throw new InvalidOperationException(string.Format(WorkspacesResources._0_is_not_part_of_the_workspace, projectId));

/// <summary>
Expand Down

0 comments on commit 497f9d6

Please sign in to comment.