Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove implicit unsafe cast in foreach #74747

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,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 @@ -542,9 +544,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 @@ -560,8 +563,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
Loading